Copyright | (c) 2016 Stephen Diehl (c) 20016-2018 Serokell (c) 2018 Kowainik |
---|---|
License | MIT |
Maintainer | Kowainik <xrom.xkov@gmail.com> |
Safe Haskell | Safe |
Language | Haskell2010 |
This module contains safe functions to work with list type in terms of NonEmpty
.
Synopsis
- viaNonEmpty :: (NonEmpty a -> b) -> [a] -> Maybe b
- whenNotNull :: Applicative f => [a] -> (NonEmpty a -> f ()) -> f ()
- whenNotNullM :: Monad m => m [a] -> (NonEmpty a -> m ()) -> m ()
Documentation
viaNonEmpty :: (NonEmpty a -> b) -> [a] -> Maybe b Source #
For safe work with lists using functinons for NonEmpty
.
>>>
viaNonEmpty head [1]
Just 1>>>
viaNonEmpty head []
Nothing
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
.