this seems nice.
It just seems that the obvious way to do it would be:
def tap(iter_, func):
for item in iter_:
func(item)
yield item
I think it can be nice, but more as cookbook material than an actual
itertools function.
On Sun, 25 Oct 2020 at 14:38, <2qdxy4rzwzuui...@pot
On 2020-10-25 at 16:34:14 +,
George Harding wrote:
> some_iter = map(lambda x: x if print(x) else x, some_iter)
>
> The tuple has a ~50% overhead, the case statement ~15%, compared to the
> generator.
def print_first(x):
print(x)
return x
new_iter = map(print_first,
less awkward is:
some_iter = map(lambda x: x if print(x) else x, some_iter)
The tuple has a ~50% overhead, the case statement ~15%, compared to the
generator.
I think that the less awkward syntax solves the problem fine (if you can
come up with it). I like that it's explicit rather than requirin
This seems like it might be a reasonable thing to have in intertools? It's
not hard to write this sort of thing with map:
some_iter = map(lambda x: (print(x), x)[1], some_iter)
But it's a little awkward. (Though maybe I'm missing a less awkward way to
do that.)
Java has Stream.peek for similar f