fastdispatch

CI Deploy to GitHub Pages

Wrapper for plum dispatch to make it more compatible with fastcore’s typedispatch. Hopefully this is just temporary, and instead the functionality here will be moved into plum.

Install

pip install fastdispatch

How to use

fastdispatch works just like plum, with a few extensions. We recommend reading through their very informative docs, however, here’s a quick example to get started:

from fastcore.test import *
from fastdispatch import *

Decorate type annotated Python functions with fastdispatch.dispatch to add them as methods to a dispatched function (following Julia’s terminology):

@dispatch
def f(x: str): return "This is a string!"

@dispatch
def f(x: int): return "This is an integer!"
f('1')
'This is a string!'
f(1)
'This is an integer!'

If there’s no matching method, plum.NotFoundLookupError is raised:

test_fail(lambda: f(1.0), contains='For function "f", signature Signature(builtins.float) could not be resolved.')