[Python-ideas] __len__() for map()

David Mertz mertz at gnosis.cx
Sat Dec 1 12:28:16 EST 2018

Other than being able to ask len(), are there any advantages to a slightly
less opaque map()? Getting the actual result of applying the function to
the element is necessarily either eager or lazy, you can't have both.

On Sat, Dec 1, 2018, 12:24 PM Steven D'Aprano <steve at pearwood.info wrote:

> On Sat, Dec 01, 2018 at 12:06:23PM -0500, David Mertz wrote:
> > Given that the anti-fix is just as simple and currently available, I
> don't
> > see why we'd want a change:
> >
> > # map->sequence
> > mo = list(mo)
> >
> > FWIW, I actually do write exactly that code fairly often, it's not hard.
> Sure, but that makes a copy of the original data and means you lose the
> benefit of map being lazy.
> Naturally we will always have the ability to call list and eagerly
> convert to a sequence, but these proposals are for a way of getting the
> advantages of sequence-like behaviour while still keeping the advantages
> of laziness.
> With iterators, the only way to get that advantage of laziness is
> to give up the ability to query length, random access to items, etc even
> when the underlying data is a sequence and that information would have
> been readily available. We can, at least sometimes, have the best of
> both worlds. Maybe.
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181201/8d6d5f2d/attachment.html>

More information about the Python-ideas mailing list