0

Given a simple curried function

import toolz

@toolz.curry
def mklist(x, y, z):
    return [x, y, z]

obviously calling mklist(x=1, y=2)(z=3) works.

What I would like to be able to do is to call the function like so: mklist(x=1, y=2)(3), where z gets bound to 3.

This errors with TypeError: mklist() got multiple values for argument 'x' since passing a positional argument apparently tries to assign the argument to the first paramter (x).

How can it be made so that the final positional argument of a curried function gets passed to the last remaining parameter?

upgrd
  • 720
  • 7
  • 16
  • I don't think keyword arguments mix well with non-keyword arguments. You ought to be able to write `mklist(1, 2)(3)`. – Frank Yellin Apr 28 '23 at 06:12
  • I believe you could try to implement something like that by meta-programming with [inspect and signatures](https://docs.python.org/3/library/inspect.html#inspect.Signature.parameters), but since you already use another tool, it may be hard to achieve. – Pipetus May 08 '23 at 17:34

0 Answers0