3 ms·
Unsurprising for a Haskeller, but he forgot the fourth and likely most common use of for loops: iterative code that has side effects. In haskell, this is done
by yummyfajitas 15y ago
Unsurprising for a Haskeller, but he forgot the fourth and likely most common use of for loops: iterative code that has side effects.
In haskell, this is done as follows:
sequence_ (map (\x -> putStrLn (show x)) [1..10])
This is equivalent to:
for i in range(1,11):
print str(x)
However, in my experience, this is a highly uncommon use of for loops. I've almost never done it, either in haskell or in python. Consider the side effectful code:
for line in open("urls.txt").readlines():
scrape_url(line)
Do I really need to do this in order?