Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
Utility functions to work with lists.
- list :: [b] -> (a -> b) -> [a] -> [b]
- ordNub :: Ord a => [a] -> [a]
- sortBy :: (a -> a -> Ordering) -> [a] -> [a]
- sortOn :: Ord b => (a -> b) -> [a] -> [a]
- sortWith :: Ord b => (a -> b) -> [a] -> [a]
- unzip :: [(a, b)] -> ([a], [b])
- unzip3 :: [(a, b, c)] -> ([a], [b], [c])
- whenNotNull :: Applicative f => [a] -> (NonEmpty a -> f ()) -> f ()
- whenNotNullM :: Monad m => m [a] -> (NonEmpty a -> m ()) -> m ()
- zip :: [a] -> [b] -> [(a, b)]
- zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
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]
sortOn :: Ord b => (a -> b) -> [a] -> [a] #
Sort a list by comparing the results of a key function applied to each
element. sortOn f
is equivalent to sortBy (comparing f)
, but has the
performance advantage of only evaluating f
once for each element in the
input list. This is called the decorate-sort-undecorate paradigm, or
Schwartzian transform.
Since: 4.8.0.0
sortWith :: Ord b => (a -> b) -> [a] -> [a] #
The sortWith
function sorts a list of elements using the
user supplied function to project something out of each element
unzip :: [(a, b)] -> ([a], [b]) #
unzip
transforms a list of pairs into a list of first components
and a list of second components.
whenNotNull :: Applicative f => [a] -> (NonEmpty a -> f ()) -> f () Source #
Performs given action over NonEmpty
list if given list is non empty.
whenNotNullM :: Monad m => m [a] -> (NonEmpty a -> m ()) -> m () Source #
Monadic version of whenNotNull
.