I'm basically looking for the find
analogue of filterM
:
findM :: (a -> m Bool) -> [a] -> m (Maybe a)
but I haven't been able to write it myself using find
and some sort of lifting function. I'm currently doing it via Data.Maybe.listToMaybe
:
x <- filterM f list
return $ listToMaybe x
which works, but it seems like I should be able to do it directly with find
.
Edit: Found some stuff on hackage: Control.Monad.Loops.firstM and Control.Monad.TM.findM both do what I want