StrictList

Description

Most basic operations like fmap, filter, <*> can only be implemented efficiently by producing an intermediate list in reversed order and then reversing it to the original order. These intermediate reversed functions are exposed by the API, because they very well may be useful for efficient implementations of data-structures built on top of list. E.g., the "deque" package exploits them heavily.

One useful rule of thumb would be that whenever you see that a function has a reversed counterpart, that counterpart is faster and hence if you don't care about the order or intend to reverse the list further down the line, you should give preference to that counterpart.

The typical toList and fromList conversions are provided by means of the Foldable and IsList instances.

Synopsis

Documentation

data List a Source #

Constructors

 Cons !a !(List a) Nil
Instances

reverse :: List a -> List a Source #

Reverse the list.

take :: Int -> List a -> List a Source #

Leave only the specified amount of elements.

takeReversed :: Int -> List a -> List a Source #

Leave only the specified amount of elements, in reverse order.

drop :: Int -> List a -> List a Source #

Leave only the elements after the specified amount of first elements.

filter :: (a -> Bool) -> List a -> List a Source #

Leave only the elements satisfying the predicate.

filterReversed :: (a -> Bool) -> List a -> List a Source #

Leave only the elements satisfying the predicate, producing a list in reversed order.

takeWhile :: (a -> Bool) -> List a -> List a Source #

Leave only the first elements satisfying the predicate.

takeWhileReversed :: (a -> Bool) -> List a -> List a Source #

Leave only the first elements satisfying the predicate, producing a list in reversed order.

dropWhile :: (a -> Bool) -> List a -> List a Source #

Drop the first elements satisfying the predicate.

span :: (a -> Bool) -> List a -> (List a, List a) Source #

An optimized version of the same predicate applied to takeWhile and dropWhile. IOW,

span predicate list = (takeWhile predicate list, dropWhile predicate list)

spanReversed :: (a -> Bool) -> List a -> (List a, List a) Source #

Same as span, only with the first list in reverse order.

break :: (a -> Bool) -> List a -> (List a, List a) Source #

An opposite version of span. I.e.,

break predicate = span (not . predicate)

breakReversed :: (a -> Bool) -> List a -> (List a, List a) Source #

Same as break, only with the first list in reverse order.

takeWhileFromEnding :: (a -> Bool) -> List a -> List a Source #

Same as (takeWhile predicate . reverse). E.g.,

>>> takeWhileFromEnding (> 2) (fromList [1,4,2,3,4,5])
fromList [5,4,3]


dropWhileFromEnding :: (a -> Bool) -> List a -> List a Source #

Same as (dropWhile predicate . reverse). E.g.,

>>> dropWhileFromEnding (> 2) (fromList [1,4,2,3,4,5])
fromList [2,4,1]


uncons :: List a -> Maybe (a, List a) Source #

Get the first element and the remainder of the list if it's not empty.

head :: List a -> Maybe a Source #

Get the first element, if list is not empty.

last :: List a -> Maybe a Source #

Get the last element, if list is not empty.

tail :: List a -> List a Source #

Get all elements of the list but the first one.

init :: List a -> List a Source #

Get all elements but the last one.

initReversed :: List a -> List a Source #

Get all elements but the last one, producing the results in reverse order.

apZipping :: List (a -> b) -> List a -> List b Source #

Apply the functions in the left list to elements in the right one.

apZippingReversed :: List (a -> b) -> List a -> List b Source #

Apply the functions in the left list to elements in the right one, producing a list of results in reversed order.

Reversed intermediate functions used in instances

fromListReversed :: [a] -> List a Source #

Construct from a lazy list in reversed order.

prependReversed :: List a -> List a -> List a Source #

Add elements of the left list in reverse order in the beginning of the right list.

mapReversed :: (a -> b) -> List a -> List b Source #

Map producing a list in reversed order.

apReversed :: List (a -> b) -> List a -> List b Source #

Apply the functions in the left list to every element in the right one, producing a list of results in reversed order.

explodeReversed :: (a -> List b) -> List a -> List b Source #

Use a function to produce a list of lists and then concat them sequentially, producing the results in reversed order.

joinReversed :: List (List a) -> List a Source #

Join (concat) producing results in reversed order.