On Sun, Oct 13, 2019, 6:12 PM Andrew Barnert

>     from functools import singledispatch
>     @singledispatch
>     def just_add_it(collection, value):
>         raise TypeError(blah blah)
>
> Now you can explicitly register methods like this:
>
>     just_add_it.register(set, set.add)
>     just_add_it.register(list, list.append)
>     just_add_it.register(Queue, Queue.put)
>     @just_add_it.register(MyCollection)
>     def _(stuff, item):
>         # ....
>
> More generally, both you and Steve Jorgensen seem to be proposing a bunch
> of things that already exist. It’s worth taking the time to figure out
> what’s already there before suggesting changes.
>

Sort of. I proposed the spelling as .register() because single dispatch was
the obvious way to implement it.

The `just_add_it()` function would be a new thing, whether in a personal
toolkit or in the collections module. Hopefully with a better name than my
placeholder. But yeah, given that your three line implementation is
basically feature complete, probably there's no reason it needs to live in
stdlib.

My point was really just that a function could be more flexible than a
method added to every collection type, or even than a protocol.

>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/HQUWWFAEOQCKKBFRT7GEOK5ZDD7O37WA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to