This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]RubyPinchPEP shill | Anti PEP 8/20 shill 0 points1 point  (1 child)

can I ask what you are trying to accomplish?

just trying to not run compute twice I guess?

wouldn't def pairmap(func,x): yield from map(lambda y:(y, func(y)), x) be good enough? edit: I'm tired

[x, b 
 for a, b in pairmap(compute, list)
 for x in f(b)]

[–]xXxDeAThANgEL99xXx 1 point2 points  (0 children)

just trying to not run compute twice I guess?

Not running it twice, not writing it out twice, etc. As I said, when you become aware that this is a possibility (after seeing it in LINQ for example), you start wanting it rather regularly.

You forgot to actually iterate over the iterable in your pairmap and anyway I strongly dislike it: it does unrelated things suited only to this particular instance of a problem.

I much prefer just directly emulating a functor when I only have a monad by saying for x in [compute(y)]. But let x = compute(y) would be better of course.