Module DA.List.Total

Functions

head

: [a] -> Optional a

Return the first element of a list. Return None if list is empty.

tail

: [a] -> Optional [a]

Return all but the first element of a list. Return None if list is empty.

last

: [a] -> Optional a

Extract the last element of a list. Returns None if list is empty.

init

: [a] -> Optional [a]

Return all the elements of a list except the last one. Returns None if list is empty.

(!!)

: [a] -> Int -> Optional a

Return the nth element of a list. Return None if index is out of bounds.

foldl1

: (a -> a -> a) -> [a] -> Optional a

Fold left starting with the head of the list. For example, foldl1 f [a,b,c] = f (f a b) c. Return None if list is empty.

foldr1

: (a -> a -> a) -> [a] -> Optional a

Fold right starting with the last element of the list. For example, foldr1 f [a,b,c] = f a (f b c)

foldBalanced1

: (a -> a -> a) -> [a] -> Optional a

Fold a non-empty list in a balanced way. Balanced means that each element has approximately the same depth in the operator tree. Approximately the same depth means that the difference between maximum and minimum depth is at most 1. The accumulation operation must be associative and commutative in order to get the same result as foldl1 or foldr1.

Return None if list is empty.

minimumBy

: (a -> a -> Ordering) -> [a] -> Optional a

Return the least element of a list according to the given comparison function. Return None if list is empty.

maximumBy

: (a -> a -> Ordering) -> [a] -> Optional a

Return the greatest element of a list according to the given comparison function. Return None if list is empty.

minimumOn

: Ord k => (a -> k) -> [a] -> Optional a

Return the least element of a list when comparing by a key function. For example minimumOn (\(x,y) -> x + y) [(1,2), (2,0)] == Some (2,0). Return None if list is empty.

maximumOn

: Ord k => (a -> k) -> [a] -> Optional a

Return the greatest element of a list when comparing by a key function. For example maximumOn (\(x,y) -> x + y) [(1,2), (2,0)] == Some (1,2). Return None if list is empty.