I have definitely hit this difficulty many times. The part of the code that
"just puts something in the collection" doesn't need to care conceptually
about the kind of collection. Taking the data back out somewhere else more
often needs to worry about order, efficiency, concurrency, etc.

But as I see other comments, I think an external function makes more sense.
Sure, list and set could grow a common method. But then what about deque or
queue? What about the excellent third part sortedcontainers package? Or a
Panda Series? Do all of these need to grow that same method?

I think more flexible would be a callable that also provided a way to
register how to "just put the item in the container." This could be
expanded by users only as far as was useful to them.

Sufficiently refined, I can imagine wanting such a thing in the collections
module itself.

So maybe an API like:

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, lambda stuff, item: ...)


# Later
just_add_it(the_things, item)

Then a user can decide where to weigh issues like sets not allowing mutable
objects or queues being finite size.




On Sun, Oct 13, 2019, 5:22 PM Steve Jorgensen <ste...@stevej.name> wrote:

> IMO, the problem with the "you can create your own" solution is that this
> is such a common thing that it seems like it should simply be present
> rather than having a vast number of applications and libraries each
> implementing their own unique solutions.
> _______________________________________________
> 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/FUUZZ6BR5NXNQYKVSGZI63ELJ2CT7UK4/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
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/2PLF3EMEWUT2WTSOWMGQ6DAHVR5A6DJJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to