[Python-ideas] __len__() for map()
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
> > 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.
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas