I have a function which signature is String -> String -> IO (Maybe String)
Now, I use this function to build values for a dictionary and I end up with: [(String,IO (Maybe String))]
I have to analyze the values in the dictionary and based on the result return the appropriate key. I was hoping to just use filter on the Map to step through it but I can’t think of a way to extract that IO action on the fly. So how do I map/filter through the dictionary running the IO action and based on the result of the IO action’s value return appropriate key of the dictionary?? Is there an easy way of doing it or I just got myself in a mess?
Thanks.
Perhaps the solution is to use
sequencewith something likethen you can simply use
liftMto apply your filter to the resultingIO [(String,Maybe String)].liftMis in Control.Monad. Alternatively, in do notationPerhaps some refactoring is in order. Often when working with monads you want to use
mapMinstead ofmap.There is also a
filterMfunction in Control.Monad. It might be what you need.Edit: it was pointed out in comments that
is equivalent to
so