"""
class (Monad m) => MonadZero m where
mzero :: m a
+ mfilter :: (a -> Boolean) -> m a -> m a
+
+ mfilter p m = m >>= (\x -> if p x then return x else mzero)
"Injects a boolean test to a type beloning to `MonadZero`."
guard :: MonadZero m => Boolean -> m ()
instance MonadE [] where
bindE l f = concatMap f l
+
+/// MZeroE ///
+
+class (MonadE m, MonadZero m) => MonadZeroE m where
+ filter :: (a -> <e> Boolean) -> m a -> <e> m a
+
+ filter p m = m `bindE` (\x -> if p x then return x else mzero)
+instance MonadZeroE [] where
+ filter = filterList
+
+instance MonadZeroE Maybe where
+ filter p (Just x) | not (p x) = Nothing
+ filter _ m = m
+
/// Category ///
"Identity function."
`filter pred lst` returns those elements of `lst` that the predicate `pred` accepts. For example
filter (> 3) [1, 2, 3, 4, 5, 6] = [4, 5, 6]
-"""
+"""
@inline
-filter :: (a -> <e> Boolean) -> [a] -> <e> [a]
-filter p l = build (\empty cons -> foldl (\cur x -> if p x then cons cur x else cur) empty l)
+filterList :: (a -> <e> Boolean) -> [a] -> <e> [a]
+filterList p l = build (\empty cons -> foldl (\cur x -> if p x then cons cur x else cur) empty l)
"""
Takes those elements of the input list that match `(Just x)` and adds the contents to the resulting list. For example,