rio-0.1.21.0: A standard library for Haskell

RIO.List.Partial

Description

List partial functions. Import as:

import qualified RIO.List.Partial as L'
Synopsis

# Basic functions

head :: [a] -> a #

$$\mathcal{O}(1)$$. Extract the first element of a list, which must be non-empty.

last :: [a] -> a #

$$\mathcal{O}(n)$$. Extract the last element of a list, which must be finite and non-empty.

tail :: [a] -> [a] #

$$\mathcal{O}(1)$$. Extract the elements after the head of a list, which must be non-empty.

init :: [a] -> [a] #

$$\mathcal{O}(n)$$. Return all the elements of a list except the last one. The list must be non-empty.

# Reducing lists (folds)

foldl1 :: Foldable t => (a -> a -> a) -> t a -> a #

A variant of foldl that has no base case, and thus may only be applied to non-empty structures.

foldl1 f = foldl1 f . toList

foldl1' :: (a -> a -> a) -> [a] -> a #

A strict version of foldl1

foldr1 :: Foldable t => (a -> a -> a) -> t a -> a #

A variant of foldr that has no base case, and thus may only be applied to non-empty structures.

foldr1 f = foldr1 f . toList

## Special folds

maximum :: (Foldable t, Ord a) => t a -> a #

The largest element of a non-empty structure.

Since: base-4.8.0.0

minimum :: (Foldable t, Ord a) => t a -> a #

The least element of a non-empty structure.

Since: base-4.8.0.0

maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a #

The largest element of a non-empty structure with respect to the given comparison function.

minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a #

The least element of a non-empty structure with respect to the given comparison function.

# Building lists

## Scans

scanl1 :: (a -> a -> a) -> [a] -> [a] #

$$\mathcal{O}(n)$$. scanl1 is a variant of scanl that has no starting value argument:

scanl1 f [x1, x2, ...] == [x1, x1 f x2, ...]

scanr1 :: (a -> a -> a) -> [a] -> [a] #

$$\mathcal{O}(n)$$. scanr1 is a variant of scanr that has no starting value argument.

# Indexing lists

(!!) :: [a] -> Int -> a infixl 9 #

List index (subscript) operator, starting from 0. It is an instance of the more general genericIndex, which takes an index of any integral type.