Module

RRBList

Package
purescript-rrb-list
Repository
funkia/purescript-rrb-list

#fromFoldable Source

fromFoldable :: forall f. Foldable f => f ~> List

Convert a Foldable structure into an List.

Running time: O(n).

#toUnfoldable Source

toUnfoldable :: forall f. Unfoldable f => List ~> f

Convert a List into an Unfoldable structure.

#singleton Source

singleton :: forall a. a -> List a

Create a list of one element

Running time: O(1).

#(..) Source

Operator alias for RRBList.range (non-associative / precedence 8)

An infix synonym for range.

#range Source

range :: Int -> Int -> List Int

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

Running time: O(n).

#replicate Source

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

Create a list containing a value repeated the specified number of times.

Running time: O(n).

#some Source

some :: forall a f. Alternative f => Lazy (f (List a)) => f a -> f (List a)

Attempt a computation multiple times, requiring at least one success.

The Lazy constraint is used to generate the result lazily, to ensure termination.

#many Source

many :: forall a f. Alternative f => Lazy (f (List a)) => f a -> f (List a)

Attempt a computation multiple times, returning as many successful results as possible (possibly zero).

The Lazy constraint is used to generate the result lazily, to ensure termination.

#null Source

null :: forall a. List a -> Boolean

Test whether a list is empty.

Running time: O(1).

#length Source

length :: forall a. List a -> Int

Get the number of elements in a list.

#nil Source

nil :: forall a. List a

Create a list of zero elements

Running time: O(1).

#(:) Source

Operator alias for RRBList.cons (right-associative / precedence 6)

An infix alias for cons.

Note, the running time of this function is O(log(n)), practically constant.

#cons Source

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

Attaches an element to the front of a list.

Running time: O(1).

#snoc Source

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

Append an element to the end of a list.

Running time: O(1).

#insert Source

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

Insert an element into a sorted list.

#insertBy Source

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.

#head Source

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 Source

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

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

Running time: O(1).

#tail Source

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

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

Running time: O(1)

#init Source

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

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

Running time: O(1)

#uncons Source

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

Break a list into its first element and remaining elements.

Running time: O(1)

#unsnoc Source

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

Break a list into its last element and all preceding elements.

Running time: O(1)

#(!!) Source

Operator alias for RRBList.index (left-associative / precedence 8)

An infix version of index.

#index Source

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

This function provides a safe way to read a value at a particular index from a list.

Running time: O(log(n)), effectively constant.

#elemIndex Source

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

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

Running time: O(i), where i is the index of the element.

#elemLastIndex Source

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

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

#findIndex Source

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

Find the first index for which a predicate holds.

#findLastIndex Source

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

Find the last index for which a predicate holds.

#insertAt Source

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

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

If the specified index is one greater than the length of the list, the element is appended

Running time: O(log(n)).

#deleteAt Source

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

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

Running time: O(log(n)).

#updateAt Source

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

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

Running time: O(log(n)).

#updateAtIndices Source

updateAtIndices :: forall a t. Foldable t => t (Tuple Int a) -> List a -> List a

Change the elements at the specified indices in index/value pairs. Out-of-bounds indices will have no effect.

Running time: O(m * log(n)), where m is the number of indices and n is the length of the list.

#modifyAt Source

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

Apply a function to the element at the specified index, creating a new list, or returning Nothing if the index is out of bounds.

Running time: O(log(n)).

#modifyAtIndices Source

modifyAtIndices :: forall a t. Foldable t => t Int -> (a -> a) -> List a -> List a

Apply a function to the element at the specified indices, creating a new array. Out-of-bounds indices will have no effect.

Running time: O(m * log(n)), where m is the number of indices and n is the length of the list.

#alterAt Source

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.

#reverse Source

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

Reverse a list, creating a new list.

#concat Source

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

Flatten a list of lists, creating a new list.

#concatMap Source

concatMap :: forall b a. (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*log(m), where n is the length of the given list and m is the length of the lists returned by the function.

#filter Source

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

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

Running time: O(n)

#partition Source

partition :: forall a. (a -> Boolean) -> List a -> { no :: List a, yes :: List a }

Partition a list using a predicate function, creating a set of new lists. One for the values satisfying the predicate function and one for values that don't.

#filterA Source

filterA :: forall f a. Applicative f => (a -> f Boolean) -> List a -> f (List a)

Filter where the predicate returns a Boolean in some Applicative.

#mapMaybe Source

mapMaybe :: forall b a. (a -> Maybe b) -> List a -> List b

Apply a function to each element in a list, keeping only the results which contain a value, creating a new list.

#catMaybes Source

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

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

#mapWithIndex Source

mapWithIndex :: forall b a. (Int -> a -> b) -> List a -> List b

Apply a function to each element in a list, supplying a generated zero-based index integer along with the element, creating a list with the new elements.

#sort Source

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

Sort the elements of a list in increasing order, creating a new list.

Running time: O(n*log(n)).

#sortBy Source

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 partial ordering, creating a new list.

Running time: O(n*log(n)).

#sortWith Source

sortWith :: forall b a. Ord b => (a -> b) -> List a -> List a

Sort the elements of a list in increasing order, where elements are sorted based on a projection

Running time: O(n*log(n)).

#slice Source

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

Extract a sublist by a start and end index.

Running time: O(log(n)).

#take Source

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

Keep only a number of elements from the start of a list, creating a new list.

#takeEnd Source

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

Keep only a number of elements from the end of a list, creating a new list.

#takeWhile Source

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

Calculate the longest initial sublist for which all element satisfy the specified predicate, creating a new list.

#drop Source

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

Drop a number of elements from the start of a list, creating a new list.

#dropEnd Source

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

Drop a number of elements from the start of a list, creating a new list.

#dropWhile Source

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

Remove the longest initial sublist for which all element satisfy the specified predicate, creating a new list.

#span Source

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

Split a list into two parts:

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

Running time: O(n).

#group Source

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

Group equal, consecutive elements of a list into lists.

#group' Source

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

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

#groupBy Source

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

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

#nub Source

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

Remove the duplicates from a list, creating a new list.

Running time: O(n).

#nubBy Source

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

Remove the duplicates from a list, where element equality is determined by the specified equivalence relation, creating a new list.

#union Source

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

Calculate the union of two lists. Note that duplicates in the first list are preserved while duplicates in the second list are removed.

Running time: O(n^2)

#unionBy Source

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. Note that duplicates in the first list are preserved while duplicates in the second list are removed.

Running time: O(n^2).

#delete Source

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

Delete the first element of a list which is equal to the specified value, creating a new list.

Running time: O(n)

#deleteBy Source

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

Delete the first element of a list which matches the specified value, under the equivalence relation provided in the first argument, creating a new list.

Running time: O(n).

#(\\) Source

Operator alias for RRBList.difference (non-associative / precedence 5)

#difference Source

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, creating a new list.

Running time: O(n*m), where n is the length of the first list, and m is the length of the second.

#intersect Source

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

Calculate the intersection of two lists, creating a new list. Note that duplicates in the first list are preserved while duplicates in the second list are removed.

Running time: O(n*m).

#intersectBy Source

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

Calculate the intersection of two lists, using the specified equivalence relation to compare elements, creating a new list. Note that duplicates in the first list are preserved while duplicates in the second list are removed.

Running time: O(n*m).

#zipWith Source

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

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

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

Running time: O(n).

#zipWithA Source

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

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

Running time: O(n).

#zip Source

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

Takes two lists and returns an list of corresponding pairs. If one input list is short, excess elements of the longer list are discarded.

Running time: O(n).

#unzip Source

unzip :: forall b a. 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.

Running time: O(n).

#foldM Source

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

Perform a fold using a monadic step function.

#foldRecM Source

foldRecM :: forall b a m. MonadRec m => (a -> b -> m a) -> a -> List b -> m a

#unsafeIndex Source

unsafeIndex :: forall a. Partial => List a -> Int -> a

Find the element of a list at the specified index.

Using unsafeIndex with an out-of-range index will not immediately raise a runtime error. Instead, the result will be undefined. Most attempts to subsequently use the result will cause a runtime error, of course, but this is not guaranteed, and is dependent on the backend; some programs will continue to run as if nothing is wrong. For example, in the JavaScript backend, the expression unsafePartial (unsafeIndex (singleton true) 1) has type Boolean; since this expression evaluates to undefined, attempting to use it in an if statement will cause the else branch to be taken.

Running time: O(log(n)), effectively constant.

Re-exports from Data.Foldable

#foldMap Source

foldMap :: forall f m a. Foldable f => Monoid m => (a -> m) -> f a -> m

#foldl Source

foldl :: forall f b a. Foldable f => (b -> a -> b) -> b -> f a -> b

#foldr Source

foldr :: forall f b a. Foldable f => (a -> b -> b) -> b -> f a -> b

#notElem Source

notElem :: forall f a. Foldable f => Eq a => a -> f a -> Boolean

Test whether a value is not an element of a data structure.

#intercalate Source

intercalate :: forall m f. Foldable f => Monoid m => m -> f m -> m

Fold a data structure, accumulating values in some Monoid, combining adjacent elements using the specified separator.

#fold Source

fold :: forall m f. Foldable f => Monoid m => f m -> m

Fold a data structure, accumulating values in some Monoid.

#findMap Source

findMap :: forall f b a. Foldable f => (a -> Maybe b) -> f a -> Maybe b

Try to find an element in a data structure which satisfies a predicate mapping.

#find Source

find :: forall f a. Foldable f => (a -> Boolean) -> f a -> Maybe a

Try to find an element in a data structure which satisfies a predicate.

#elem Source

elem :: forall f a. Foldable f => Eq a => a -> f a -> Boolean

Test whether a value is an element of a data structure.

#any Source

any :: forall f b a. Foldable f => HeytingAlgebra b => (a -> b) -> f a -> b

any f is the same as or <<< map f; map a function over the structure, and then get the disjunction of the results.

#all Source

all :: forall f b a. Foldable f => HeytingAlgebra b => (a -> b) -> f a -> b

all f is the same as and <<< map f; map a function over the structure, and then get the conjunction of the results.

Re-exports from Data.Traversable

#scanr Source

scanr :: forall f b a. Traversable f => (a -> b -> b) -> b -> f a -> f b

Fold a data structure from the right, keeping all intermediate results instead of only the final result. Note that the initial value does not appear in the result (unlike Haskell's Prelude.scanr).

scanr (+) 0  [1,2,3] = [1,3,6]
scanr (flip (-)) 10 [1,2,3] = [4,5,7]

#scanl Source

scanl :: forall f b a. Traversable f => (b -> a -> b) -> b -> f a -> f b

Fold a data structure from the left, keeping all intermediate results instead of only the final result. Note that the initial value does not appear in the result (unlike Haskell's Prelude.scanl).

scanl (+) 0  [1,2,3] = [1,3,6]
scanl (-) 10 [1,2,3] = [9,7,4]

Re-exports from RRBList.Types