3 ms·
Isn't this behavior in Python already via the functools module? Can't look it up right now but I'm pretty sure it's there.
by sleavey 7y ago
Isn't this behavior in Python already via the functools module? Can't look it up right now but I'm pretty sure it's there.
- joshuamorton 7y agoFunctions.singledispatch allows overloading based on the type of the first argument, but doesn't allow complex overloads, like arg-count based or multi-type based.
- emidln 7y agoThis is not hard to write if you care about it (dispatching on data in addition to dispatching on type). Clojure-style multimethods with python-style type dispatch or data result dispatch can be had for under 150 lines. It's not particularly useful unless you are porting code or otherwise writing very unpythonic code.