> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# Multimethod

> A decorator for adding multiple argument dispatching to functions.

Web page: https://eugo.io/docs/ganymede/demo_notebooks/data_structures/multimethod/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/data_structures/multimethod/multimethod.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/data_structures/multimethod.ipynb)

Description:
- A decorator for adding multiple argument dispatching to functions. The decorator creates a multimethod object as needed, and registers the function with its annotations.

Resources:
- [GitHub] https://github.com/coady/multimethod
- [Examples] https://coady.github.io/multimethod/user-guide/examples.html

## Example 1

Map a signature to a function. 

```python
from multimethod import multimethod
import operator

classic_div = multimethod(operator.truediv)
classic_div[int, int] = operator.floordiv
classic_div
```

## Example 2

Introspect type annotations and use the name to find existing multimethods.

```python
from multimethod import multimethod
import itertools
from collections.abc import Iterable, Sequence


@multimethod
def chunks(values: Iterable, size):
    it = iter(values)
    return iter(lambda: list(itertools.islice(it, size)), [])


@multimethod
def chunks(values: Sequence, size):
    for index in range(0, len(values), size):
        yield values[index : index + size]


list(chunks(iter('abcde'), 3))
```
