I have a function f that goes something like this:
f = do
x1 <- g
x2 <- g
x3 <- g
...
xn <- g
return [x1,x2,x3,..., xn] --or (x1,x2,x3,..., xn)
This requires many lines of code and I have a feeling this can be done prettier. I would like to know if there is a way to do something like this:
f = do
[x,y,z] <- [g,g,g]
return [x,y,z]
Use sequence
and replicate
:
f = do
xs <- sequence $ replicate n g
return xs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With