Skip to content

Latest commit

 

History

History
207 lines (134 loc) · 3.05 KB

List.md

File metadata and controls

207 lines (134 loc) · 3.05 KB

Module Erl.Data.List

List

data List :: * -> *
Instances
(Show a) => Show (List a)
(Eq a) => Eq (List a)
Semigroup (List a)
Monoid (List a)
Functor List
Foldable List
Unfoldable List
Traversable List
Apply List
Applicative List
Bind List
Monad List
Alt List
Plus List
Alternative List
MonadZero List
MonadPlus List

nil

nil :: forall a. List a

cons

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

(:)

infixr 6 cons as :

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)

(..)

infix 8 range as ..

An infix synonym for range.

range

range :: Int -> Int -> List Int

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

null

null :: forall a. List a -> Boolean

Test whether a list is empty.

Running time: O(1)

length

length :: forall a. List a -> Int

Get the length of a list

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)

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)

reverse

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

otherwise = go (n + 1) xs 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.

filter

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

Filter a list, keeping the elements which satisfy a predicate function.

Running time: O(n)