filtermap functional below allows to perform the standard
filter operations in one go. The mapping function has to return a
Maybe monad, and values of
Nothing are filtered out.
- -- Prepend an element to a list if available. Leave the list as it is if the
- -- first argument is Nothing.
- maybecons :: Maybe t -> [t] -> [t]
- maybecons Nothing l = l
- maybecons (Just e) l = e : l
- -- Variant of map which deletes elements if the map function returns Nothing.
- filtermap :: (a -> Maybe b) -> [a] -> [b]
- filtermap _  = 
- filtermap f (a:as) = maybecons (f a) $ filtermap f as
You need to login to post a comment.