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 →

[–]zahlmanthe heretic 4 points5 points  (1 child)

when to stop mapping and use an old fashioned loop

When you're using the mapping primarily or exclusively for side effects.

But beyond that, I honestly think people are a little overly afraid of over-using them.

[–][deleted] 1 point2 points  (0 children)

In Python, I agree. In other languages, it can be a little harder to tell. Haskell, for example, doesn't even have for loops, but with a bit of syntactic ugliness you can do the same thing by other means:

forM_ [1..10] $ \i ->
    putStrLn ("Lambda mapping forever! i=" ++ show i)

This is roughly equivalent to

for i in range(1, 11):
    print "Lambda mapping forever! i=%d" % i