Module

Erl.Data.List

#toUnfoldable

toUnfoldable :: forall f a. Unfoldable f => List a -> f a

Convert a list into any unfoldable structure.

Running time: O(n)

#fromFoldable

fromFoldable :: forall f a. Foldable f => f a -> List a

Construct a list from a foldable structure.

Running time: O(n)

#singleton

singleton :: forall a. a -> List a

Create a list with a single element.

Running time: O(1)

#range

range :: Int -> Int -> List Int

Create a list containing a range of integers, including both endpoints.

#(..)

Operator alias for Erl.Data.List.range (non-associative / precedence 8)

An infix synonym for range.

#length

length :: forall a. List a -> Int

Get the length of a list

Running time: O(n)

#snoc

snoc :: forall a. List a -> a -> List a

Append an element to the end of a list, creating a new list.

Running time: O(2n)

#unsnoc

unsnoc :: forall a. List a -> Maybe { init :: List a, last :: a }

Break a list into its last element, and the preceding elements, or Nothing if the list is empty.

Running time: O(n)

#insert

insert :: forall a. Ord a => a -> List a -> List a

Insert an element into a sorted list.

Running time: O(n)

#insertBy

insertBy :: forall a. (a -> a -> Ordering) -> a -> List a -> List a

Insert an element into a sorted list, using the specified function to determine the ordering of elements.

Running time: O(n)

#head

head :: forall a. List a -> Maybe a

Get the first element in a list, or Nothing if the list is empty.

Running time: O(1).

#last

last :: forall a. List a -> Maybe a

Get the last element in a list, or Nothing if the list is empty.

Running time: O(n).

#tail

tail :: forall a. List a -> Maybe (List a)

Get all but the first element of a list, or Nothing if the list is empty.

Running time: O(1)

#init

init :: forall a. List a -> Maybe (List a)

Get all but the last element of a list, or Nothing if the list is empty.

Running time: O(n)

#index

index :: forall a. List a -> Int -> Maybe a

Get the element at the specified index, or Nothing if the index is out-of-bounds.

Running time: O(n) where n is the required index.

#(!!)

Operator alias for Erl.Data.List.index (left-associative / precedence 8)

An infix synonym for index.

#elemIndex

elemIndex :: forall a. Eq a => a -> List a -> Maybe Int

Find the index of the first element equal to the specified element.

#elemLastIndex

elemLastIndex :: forall a. Eq a => a -> List a -> Maybe Int

Find the index of the last element equal to the specified element.

#findIndex

findIndex :: forall a. (a -> Boolean) -> List a -> Maybe Int

Find the first index for which a predicate holds.

#findLastIndex

findLastIndex :: forall a. (a -> Boolean) -> List a -> Maybe Int

Find the last index for which a predicate holds.

#insertAt

insertAt :: forall a. Int -> a -> List a -> Maybe (List a)

Insert an element into a list at the specified index, returning a new list or Nothing if the index is out-of-bounds.

Running time: O(n)

#deleteAt

deleteAt :: forall a. Int -> List a -> Maybe (List a)

Delete an element from a list at the specified index, returning a new list or Nothing if the index is out-of-bounds.

Running time: O(n)

#updateAt

updateAt :: forall a. Int -> a -> List a -> Maybe (List a)

Update the element at the specified index, returning a new list or Nothing if the index is out-of-bounds.

Running time: O(n)

#modifyAt

modifyAt :: forall a. Int -> (a -> a) -> List a -> Maybe (List a)

Update the element at the specified index by applying a function to the current value, returning a new list or Nothing if the index is out-of-bounds.

Running time: O(n)

#alterAt

alterAt :: forall a. Int -> (a -> Maybe a) -> List a -> Maybe (List a)

Update or delete the element at the specified index by applying a function to the current value, returning a new list or Nothing if the index is out-of-bounds.

Running time: O(n)

#reverse

reverse :: forall a. List a -> List a

Reverse a list.

Running time: O(n)

#concat

concat :: forall a. List (List a) -> List a

Flatten a list of lists.

Running time: O(n), where n is the total number of elements.

#concatMap

concatMap :: forall a b. (a -> List b) -> List a -> List b

Apply a function to each element in a list, and flatten the results into a single, new list.

Running time: O(n), where n is the total number of elements.

#filterM

filterM :: forall a m. Monad m => (a -> m Boolean) -> List a -> m (List a)

Filter where the predicate returns a monadic Boolean.

For example:

powerSet :: forall a. [a] -> [[a]]
powerSet = filterM (const [true, false])

#catMaybes

catMaybes :: forall a. List (Maybe a) -> List a

Filter a list of optional values, keeping only the elements which contain a value.

#sort

sort :: forall a. Ord a => List a -> List a

Sort the elements of an list in increasing order.

#sortBy

sortBy :: forall a. (a -> a -> Ordering) -> List a -> List a

Sort the elements of a list in increasing order, where elements are compared using the specified ordering.

#merge

merge :: forall a. Ord a => List a -> List a -> List a

#mergeBy

mergeBy :: forall a. (a -> a -> Ordering) -> List a -> List a -> List a

#slice

slice :: forall a. Int -> Int -> List a -> List a

Extract a sublist by a start and end index.

#take

take :: forall a. Int -> List a -> List a

Take the specified number of elements from the front of a list.

Running time: O(n) where n is the number of elements to take.

#takeWhile

takeWhile :: forall a. (a -> Boolean) -> List a -> List a

Take those elements from the front of a list which match a predicate.

Running time (worst case): O(n)

#drop

drop :: forall a. Int -> List a -> List a

Drop the specified number of elements from the front of a list.

Running time: O(n) where n is the number of elements to drop.

#dropWhile

dropWhile :: forall a. (a -> Boolean) -> List a -> List a

Drop those elements from the front of a list which match a predicate.

Running time (worst case): O(n)

#span

span :: forall a. (a -> Boolean) -> List a -> { init :: List a, rest :: List a }

Split a list into two parts:

  1. the longest initial segment for which all elements satisfy the specified predicate
  2. the remaining elements

For example,

span (\n -> n % 2 == 1) (1 : 3 : 2 : 4 : 5 : Nil) == { init: (1 : 3 : Nil), rest: (2 : 4 : 5 : Nil) }

Running time: O(n)

#group

group :: forall a. Eq a => List a -> List (NonEmptyList a)

Group equal, consecutive elements of a list into lists.

For example,

group (1 : 1 : 2 : 2 : 1 : Nil) == (1 : 1 : Nil) : (2 : 2 : Nil) : (1 : Nil) : Nil

Running time: O(n)

#group'

group' :: forall a. Ord a => List a -> List (NonEmptyList a)

Sort and then group the elements of a list into lists.

group' [1,1,2,2,1] == [[1,1,1],[2,2]]

#groupBy

groupBy :: forall a. (a -> a -> Boolean) -> List a -> List (NonEmptyList a)

Group equal, consecutive elements of a list into lists, using the specified equivalence relation to determine equality.

Running time: O(n)

#nub

nub :: forall a. Eq a => List a -> List a

Remove duplicate elements from a list.

Running time: O(n^2)

#nubBy

nubBy :: forall a. (a -> a -> Boolean) -> List a -> List a

Remove duplicate elements from a list, using the specified function to determine equality of elements.

Running time: O(n^2)

#union

union :: forall a. Eq a => List a -> List a -> List a

Calculate the union of two lists.

Running time: O(n^2)

#unionBy

unionBy :: forall a. (a -> a -> Boolean) -> List a -> List a -> List a

Calculate the union of two lists, using the specified function to determine equality of elements.

Running time: O(n^2)

#delete

delete :: forall a. Eq a => a -> List a -> List a

Delete the first occurrence of an element from a list.

Running time: O(n)

#deleteBy

deleteBy :: forall a. (a -> a -> Boolean) -> a -> List a -> List a

Delete the first occurrence of an element from a list, using the specified function to determine equality of elements.

Running time: O(n)

#(\\)

Operator alias for Erl.Data.List.difference (non-associative / precedence 5)

#difference

difference :: forall a. Eq a => List a -> List a -> List a

Delete the first occurrence of each element in the second list from the first list.

Running time: O(n^2)

#intersect

intersect :: forall a. Eq a => List a -> List a -> List a

Calculate the intersection of two lists.

Running time: O(n^2)

#intersectBy

intersectBy :: forall a. (a -> a -> Boolean) -> List a -> List a -> List a

Calculate the intersection of two lists, using the specified function to determine equality of elements.

Running time: O(n^2)

#zipWith

zipWith :: forall a b c. (a -> b -> c) -> List a -> List b -> List c

Apply a function to pairs of elements at the same positions in two lists, collecting the results in a new list.

If one list is longer, elements will be discarded from the longer list.

For example

zipWith (*) (1 : 2 : 3 : Nil) (4 : 5 : 6 : 7 Nil) == 4 : 10 : 18 : Nil

Running time: O(min(m, n))

#zipWithA

zipWithA :: forall m a b c. Applicative m => (a -> b -> m c) -> List a -> List b -> m (List c)

A generalization of zipWith which accumulates results in some Applicative functor.

#zip

zip :: forall a b. List a -> List b -> List (Tuple a b)

Collect pairs of elements at the same positions in two lists.

Running time: O(min(m, n))

#transpose

transpose :: forall a. List (List a) -> List (List a)

The 'transpose' function transposes the rows and columns of its argument. For example,

transpose ((1:2:3:Nil) : (4:5:6:Nil) : Nil) ==
  ((1:4:Nil) : (2:5:Nil) : (3:6:Nil) : Nil)

If some of the rows are shorter than the following rows, their elements are skipped:

transpose ((10:11:Nil) : (20:Nil) : Nil : (30:31:32:Nil) : Nil) ==
  ((10:20:30:Nil) : (11:31:Nil) : (32:Nil) : Nil)

#unzip

unzip :: forall a b. List (Tuple a b) -> Tuple (List a) (List b)

Transforms a list of pairs into a list of first components and a list of second components.

#foldM

foldM :: forall m a b. Monad m => (a -> b -> m a) -> a -> List b -> m a

Perform a fold using a monadic step function.

Re-exports from Data.Filterable

#filter

filter :: forall f a. Filterable f => (a -> Boolean) -> f a -> f a

#filterMap

filterMap :: forall f a b. Filterable f => (a -> Maybe b) -> f a -> f b

Re-exports from Data.FunctorWithIndex

#mapWithIndex

mapWithIndex :: forall f i a b. FunctorWithIndex i f => (i -> a -> b) -> f a -> f b

Re-exports from Erl.Data.List.Types

#uncons

uncons :: forall a. List a -> Maybe { head :: a, tail :: List a }

Break a list into its first element, and the remaining elements, or Nothing if the list is empty.

Running time: O(1)

#null

null :: forall a. List a -> Boolean

Test whether a list is empty.

Running time: O(1)

#nil

nil :: forall a. List a

#cons

cons :: forall a. a -> List a -> List a

#(:)

Operator alias for Erl.Data.List.Types.cons (right-associative / precedence 6)

Modules