util-plus-0.1.0.0: A collection of commonly used utils

Data.List.Plus

Synopsis

# Documentation

module Data.List

catMaybes :: [Maybe a] -> [a] #

The catMaybes function takes a list of Maybes and returns a list of all the Just values.

#### Examples

Basic usage:

>>> catMaybes [Just 1, Nothing, Just 3]
[1,3]


When constructing a list of Maybe values, catMaybes can be used to return all of the "success" results (if the list is the result of a map, then mapMaybe would be more appropriate):

>>> import Text.Read ( readMaybe )
>>> [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
[Just 1,Nothing,Just 3]
>>> catMaybes $[readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ] [1,3]  chunksOf :: Int -> [a] -> [[a]] Source # extractLast :: a -> [a] -> ([a], a) Source # groupOn :: Eq b => (a -> b) -> [a] -> [(b, [a])] Source # groupOn' :: Eq b => (a -> (b, c)) -> [a] -> [(b, [c])] Source # groupOnSort :: Ord b => (a -> b) -> [a] -> [(b, [a])] Source # groupOnSort' :: Ord b => (a -> (b, c)) -> [a] -> [(b, [c])] Source # groupBySort :: Ord b => (b -> b -> Ordering) -> (a -> b) -> [a] -> [(b, [a])] Source # groupUnsortedOn :: forall a b. Eq b => (a -> b) -> [a] -> [(b, [a])] Source # headM :: Monad m => [a] -> m a Source # lastElems :: Int -> [a] -> [a] Source # lastM :: Monad m => [a] -> m a Source # lookupM :: (Eq a, Monad m) => (a -> String) -> a -> [(a, b)] -> m b Source # makeMapping :: (Eq a, Hashable a) => [(a, b)] -> [(a, b)] Source # mapMaybe :: (a -> Maybe b) -> [a] -> [b] # The mapMaybe function is a version of map which can throw out elements. In particular, the functional argument returns something of type Maybe b. If this is Nothing, no element is added on to the result list. If it is Just b, then b is included in the result list. #### Examples Using mapMaybe f x is a shortcut for catMaybes$ map f x in most cases:

>>> import Text.Read ( readMaybe )
>>> let readMaybeInt = readMaybe :: String -> Maybe Int
>>> mapMaybe readMaybeInt ["1", "Foo", "3"]
[1,3]
>>> catMaybes \$ map readMaybeInt ["1", "Foo", "3"]
[1,3]


If we map the Just constructor, the entire list should be returned:

>>> mapMaybe Just [1,2,3]
[1,2,3]


maximumM :: (Monad m, Ord a) => [a] -> m a Source #

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

Merge two sorted list so that the resulting list is sorted as well. and contains all elements from one of the lists. The length of the resulting list is the sum of the lengths of the given lists.

middle :: [a] -> Maybe a Source #

Computes the element in the middle of the list If the list has an even number of elements, you will get the element after the middle of the list.

minimumM :: (Monad m, Ord a) => [a] -> m a Source #

monotone :: Ord a => [a] -> Bool Source #

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

Merge the two sorted lists and remove all duplicates.

prefixesAndSuffixes :: [a] -> [([a], [a])] Source #

sconcatBy :: (Ord b, Foldable f, Semigroup s) => (a -> b) -> (a -> s) -> f a -> [(b, s)] Source #

spanTailRec :: (a -> Bool) -> [a] -> ([a], [a]) Source #

stripSuffix :: Eq a => [a] -> [a] -> Maybe [a] Source #

tryStripPrefix :: Eq a => [a] -> [a] -> [a] Source #

Strips as elements of a given prefix list as possible. Stops stripping if the prefix doesn't match anymore or is exhausted and returns the remaining string.

ungroupMay :: [(a, [b])] -> Maybe [(a, b)] Source #

withLast :: (a -> a) -> [a] -> [a] Source #