universum-0.6.1: Custom prelude used in Serokell

Safe HaskellTrustworthy
LanguageHaskell2010

List

Description

Utility functions to work with lists.

Synopsis

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]

hashNub :: (Eq a, Hashable a) => [a] -> [a] Source #

Like nub but runs in O(n * log_16(n)) time and requires Hashable.

ordNub :: Ord a => [a] -> [a] Source #

Like nub but runs in O(n * log n) time and requires Ord.

sortBy :: (a -> a -> Ordering) -> [a] -> [a] #

The sortBy function is the non-overloaded version of sort.

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.

unzip3 :: [(a, b, c)] -> ([a], [b], [c]) #

The unzip3 function takes a list of triples and returns three lists, analogous to unzip.

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.

zip :: [a] -> [b] -> [(a, b)] #

zip takes two lists and returns a list of corresponding pairs. If one input list is short, excess elements of the longer list are discarded.

zip is right-lazy:

zip [] _|_ = []

zip3 :: [a] -> [b] -> [c] -> [(a, b, c)] #

zip3 takes three lists and returns a list of triples, analogous to zip.