# library of monadic functions [was: Why no findM ? simple Cat
revisited]

**Andrew J Bromage
**
ajb@spamcop.net

*Thu, 21 Nov 2002 09:54:16 +1100*

G'day all.
On Wed, Nov 20, 2002 at 08:25:46PM +0000, Jorge Adriano wrote:
>* I think both versions can be very useful:
*>* findM :: (Monad m) => (a -> m Bool) -> [a] -> m (Maybe a)
*>* findM' :: (Monad m) => (a -> Bool) -> [m a] -> m (Maybe a)
*
I can also make a case for:
findM'' :: (Monad m) => (a -> Bool) -> [m a] -> m a
findM'' p [] = fail "findM'': not found"
findM'' p (x:xs) = p x >>= \b -> if b then return x else findM'' p xs
This goes with the philosophy that library functions shouldn't just
return Maybe.
Somewhere, somehow, there is a most general version of findM to be
found. :-)
Cheers,
Andrew Bromage