On Sat, 2010-11-27 at 02:23 +0300, Miguel Mitrofanov wrote: > findIndexM = (liftM (findIndex id) .) . mapM
Not quite. Compare:
findIndexM (\x -> print x >> return True) [1,2,3]
or
findIndexM (\x -> if x == 2 then Nothing else Just True) [1,2,3]
Possibly better:
findIndexM p = foldr (\(n, y) x ->
p y >>= \b -> if b then return $! Just $! n
else x) (return $! Nothing) .
zip (map fromIntegral [1..]))
Regards
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
