coady / multimethod

Multiple argument dispatching.
https://coady.github.io/multimethod
Other
284 stars 23 forks source link

multimethod.multimethod w/ arity of 1 #1

Closed peteut closed 5 years ago

peteut commented 5 years ago

Regarding multimethod.multimethod w/ arity of 1 consider this:

from multimethod import multimethod

def clone_of_default(x):
    raise NotImplementedError("no implementation for {} found".format(type(x))) 

clone_of = multimethod(clone_of_default)
clone_of[(int,)] = lambda x: int(x)

Adding a method like, which I tried first:

clone_of[int] = lambda x: int(x)

yields TypeError: 'type' object is not iterable.

What is the desired behaviour for arity 1?

peteut commented 5 years ago

Ok, my bad. It's according the spec.

coady commented 5 years ago

The parens can be omitted too.

clone_of[int,]
peteut commented 5 years ago

The parens can be omitted too.

clone_of[int,]

Good to know, thanks!