dharmik
@dharmik@linuxusers.in
46 following 17 followers
@dharmik As an example, here's a list comprehension that just creates a list of integers from 1 to 10 and doubles them:
[x*2 | x <- [1..10]]
You can additionally tack on predicates, so you could do the same operation, but only for the odd numbers in the range:
[x*2 | x <- [1..10], x `mod` 2 == 1]
I read about them on https://learnyouahaskell.com/starting-out#im-a-list-comprehension