Retrieving Values ​​from a List of I / O

So, I have something like:

[IO Blah, IO Blah, IO Blah] 

and I really only need a list of Blah s, how can I do this?

PS: Yes, I work in the input / output function.

+6
source share
3 answers

Use sequence .

Evaluate each action in a sequence from left to right and collect the results.

 do blahs <- sequence listOfIoBlah -- now use blahs 
+11
source

You want sequence :: Monad m => [ma] -> m [a] . It works as you expect: all actions are performed in order, the results are collected and returned. Please note that nothing is returned if all commands are not completed.

+7
source

Hoogle can be very helpful in answering such questions if you know how to formulate the question as a type, for example: http://www.haskell.org/hoogle/?hoogle=%5BIO+a%5D+-%3E+IO+% 5Ba% 5D

+7
source

Source: https://habr.com/ru/post/911457/


All Articles