About this module
This module defines lists (also known as "linked lists"), an immutable data structure meantto contain finite or infinite sets of elements of the same type.
Where should I start?
To create a list containing elements 1, 2 and 3, the easiest is to write [1,2,3].The empty list is []Once you have a list, typically, there may be a few things you wish to do with it:
Transforming lists
Do you have a list of numbers you wish to double? Try List.map. Or perhaps you only wish to keepodd numbers? Look at List.filter. Or perhaps you wish to keep this in odd positions? Look atList.filteri.
Collecting list data
Do you wish to sum all the elements of a list? Try List.reduce. Or perhaps you only wish to findthe first even number? Try List.find. Or perhaps you wish to compute its length? Try List.length.
Sorting a list
To sort a list, use List.sort. This function can adapt to your sorting criteria.Limitations of this module
What if I need more?
This module contains numerous other functions, including the all-powerful List.foldi, which willlet you apply arbitrary collections/transformations/loops based on the contents of a list.Lists are immutable, as are all base data structures in OPA -- this lets the compiler optimize numerous
operations, including concurrency and database access. If you need mutability, you should consider wrapping
your list in a Session.List provide linear access time, i.e. don't use them if you frequently need to add data at the end
or if you frequently need to access the nth element. For this purpose, you should rather use moduleArray.
| Name | Summary |
|---|---|
|
As : adding an element at the head of a list.
|
|
|
An alias for Provided for compatibility with other collections.
|
|
|
A add in a list ordered by a function of comparison.
Not tail rec, used for small list only
in this ...
|
|
|
Concatenate two lists.Performance note: if you have a list you often need to extend at the end, rath...
|
|
|
Find the value associated to a key.
|
|
|
As , but with control on the comparison function.Use this function rather than if you wish to use a...
|
|
|
Check that the list has the given lengthMore efficient that computing the length of the list and the...
|
|
|
Transform a list by applying a function to each element and flattening the result.)] will return
|
|
|
returns: +++...+++where indicates application of function.
You'll most likely not use this funct...
|
|
|
Add an element at the start of a list returns the list whose first element is and in which the rest...
|
|
|
As , but returns if the element can be found, not its index.
|
|
|
Remove the first elements of a list.
|
|
|
The empty listProvided for compatibility with other collections.
|
|
|
Check whether at least one element of an index matches a given condition.
|
|
|
Get and remove the element of a list.
|
|
|
Extract an element from a list.
|
|
|
As but the function is informed of the position of the current element.
|
|
|
Transform a list by removing some elements.
|
|
|
Transform a list, removing some elements, changing others.This function lets you loop through a list...
|
|
|
As but the function is informed of the position of the current element.
|
|
|
As but returns the element itself, not its index.
|
|
|
Find the first element of a list verifying some condition and return it after treatment.This functio...
|
|
|
Flatten a list of list into a list.Performance note: this function is much faster than successive ca...
|
|
|
Loop through a list, collecting data from the list., init)] will compute
Example: the following expr...
|
|
|
As but starting from the end.
|
|
|
As .
|
|
|
As
|
|
|
Map a list while propagating an accumulator
(l',accN) = fold_map(op, l, acc1)
is equivalent to
l' = ...
|
|
|
As .
|
|
|
As but the function is informed of the position of
the current element.
|
|
|
As but starting from the end.
|
|
|
Check whether all elements of an index match a given condition.
|
|
|
Check whether all pair of corresponding elements of the pair of list match a given condition
|
|
|
Get the element of a list.Performance note: if you are looping through a list, you should rather us...
|
|
|
Search for an element in a list.This function searches the first occurrence of an element in a list ...
|
|
|
Search for an element in a list.This function searches the first occurrence of any element matching ...
|
|
|
Create a list of elements from a function.
|
|
|
A variant on .
Slower but guarantees order of function calls.
|
|
|
Insert an item in a list at a given position.
|
|
|
Puts a constant separator between each element of the list
|
|
|
Determine if a list is empty.
|
|
|
Check whether a list is sorted, by usual order.
|
|
|
Check whether a list is sorted, projecting elements before comparing them.
|
|
|
Check whether a list is sorted, using a custom order.
|
|
|
Check whether a list is sorted, using a custom order.
|
|
|
Apply a function to all the elements of a list.By opposition to , , and their variants, this functi...
|
|
|
builds of length .
(so the last element of the list has applications of )
|
|
|
As but informs the function of the current position in the list.)] will execute , , ...
|
|
|
Compute the length of a list.Performance note: if you only need to check whether a list is empty, yo...
|
|
|
Pretty-printing an arbitrary list using a value printer as: ]
|
|
|
Transform a list by applying a function to each element.)] will return
|
|
|
Transform two lists by applying a function to each pair of elements at the same position.,)] will re...
|
|
|
Transforms two lists by applying a function to each pair of elements
|
|
|
Transform a list or give up.This function is a variant on which returns if any of the
calls to the...
|
|
|
As , but the transformation function is informed of the current position in the list.
|
|
|
Synonym to .
|
|
|
Perform sorting on a list, using the merge sort algorithm.Performance note: This algorithm has compl...
|
|
|
Perform sorting on a list, using the merge sort algorithm.Performance note: This algorithm has compl...
|
|
|
An alias for the empty list
|
|
|
As .
|
|
|
Split a list in two.)
] returns , )]
|
|
|
As but the function is informed of the position of the current element.
|
|
|
Remove the first occurrence of an element in a list.
|
|
|
As but only returns the resulting list.
|
|
|
As but only returns the resulting list.
|
|
|
As but only returns the resulting list.
|
|
|
Revert a list.
|
|
|
Revert a list and append it to another one.Performance note: This function is provided solely for pe...
|
|
|
As , but reverses the list.
|
|
|
As , but reverses the list.
|
|
|
As but in the reverse order.
|
|
|
Same as iter but in reverse order
|
|
|
As , but reverses the list.
|
|
|
As , but reverses the list.
|
|
|
Sort a list by usual order.This function uses the order defined by function . The sort algorithm use...
|
|
|
Sort a list by usual order, projecting elements before comparing them.This function first projects e...
|
|
|
Sort a list with a custom order.This is a more powerful variant of .
|
|
|
Sort a list with a custom order.This is a more powerful variant of .
|
|
|
Separate a list in two.
|
|
|
Separate a list in two
|
|
|
Separate a list in two
|
|
|
Separate a list in two halves.
|
|
|
Keep the first elements of a list.
|
|
|
Pretty-printing a list of strings as: ]
|
|
|
Pretty-printing a list of strings as: ...
|
|
|
Remove duplicates from a list.
|
|
|
As but only works on sorted lists.
|
|
|
As .
|
|
|
Separate a lists of pairs into two lists.
|
|
|
Combine two lists into a list of pairs., )] will return
|
Comments