Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
This module contains safe functions to work with list type (mostly with NonEmpty
).
- list :: [b] -> (a -> b) -> [a] -> [b]
- uncons :: [a] -> Maybe (a, [a])
- whenNotNull :: Applicative f => [a] -> (NonEmpty a -> f ()) -> f ()
- whenNotNullM :: Monad m => m [a] -> (NonEmpty a -> m ()) -> m ()
Documentation
list :: [b] -> (a -> b) -> [a] -> [b] Source #
Returns default list if given list is empty. Otherwise applies given function to every element.
>>>
list [True] even []
[True]>>>
list [True] even [1..5]
[False,True,False,True,False]
uncons :: [a] -> Maybe (a, [a]) Source #
Destructuring list into its head and tail if possible. This function is total.
>>>
uncons []
Nothing>>>
uncons [1..5]
Just (1,[2,3,4,5])>>>
uncons (5 : [1..5]) >>= \(f, l) -> pure $ f == length l
Just True
whenNotNull :: Applicative f => [a] -> (NonEmpty a -> f ()) -> f () Source #
Performs given action over NonEmpty
list if given list is non empty.
>>>
whenNotNull [] $ \(b :| _) -> print (not b)
>>>
whenNotNull [False,True] $ \(b :| _) -> print (not b)
True
whenNotNullM :: Monad m => m [a] -> (NonEmpty a -> m ()) -> m () Source #
Monadic version of whenNotNull
.