List
enum List[t: Type]Sourcecase Nilcase Cons(t, List[t])The List type.
A list is either the empty list represented by Nil, or
an element v followed by a list vs represented by v :: vs.
Instances
instance Applicative[List]Sourceinstance Collectable[List[a]]Sourceinstance Filterable[List]Sourceinstance Formattable[List[a]] with Formattable[a]Sourceinstance Traversable[List]Sourceinstance UnorderedFoldable[List]Sourceinstance Witherable[List]SourceDefinitions
Apply every function from f to every argument from x and return a list with all results.
For f = f1, f2, ... and x = x1, x2, ... the results appear in the order
f1(x1), f1(x2), ..., f2(x1), f2(x2), ....
@Terminates Returns l2 appended to l1.
The infix operator ::: is an alias for append (l1 ::: l2 = append(l1, l2)).
@Terminates Returns a new list with element x added to the front of list l.
@Terminates Returns the number of elements in l that satisfy the predicate f.
@Terminates Returns the list l with duplicates removed. The first occurrence of
an element is kept and except for the removal of subsequent duplicates
the order of l is preserved.
distinct uses the Flix's builtin equality test. Use distinctWith if you
need a custom equality test.
@Terminates Returns the list l with duplicates removed using the supplied function
f for comparison. The first occurrence of an element is kept and except
for the removal of subsequent duplicates the order of l is preserved.
@Terminates @Tailrec Returns l without the first n elements.
Returns Nil if n > length(l).
Returns l if n < 0.
@Terminates @Tailrec Returns l without the longest prefix that satisfies the predicate f.
@Terminates @Tailrec Returns true if and only if at least one element in l satisfies the predicate f.
Returns false if l is empty.
@Terminates Returns a list of every element in l that satisfies the predicate f.
@Terminates Collects the results of applying the partial function f to every element in l.
@Terminates @Tailrec Optionally returns the first element of l that satisfies the predicate f when searching from left to right.
@Terminates @Tailrec Returns the first non-None result of applying the partial function f to each element of l.
Returns None if every element of l is None.
Optionally returns the first element of l that satisfies the predicate f when searching from right to left.
Returns the result of applying f to every element in l and concatenating the results.
@Terminates Returns the concatenation of the elements in l.
Returns the result of applying combine to all the elements in l, using empty as the initial value.
@Terminates Alias for foldLeft2.
@Terminates @Tailrec Applies f to a start value s and all elements in l going from left to right.
That is, the result is of the form: f(...f(f(s, x1), x2)..., xn).
@Terminates @Tailrec Accumulates the result of applying f pairwise to the elements of l1 and l2
starting with the initial value c and going from left to right.
@Terminates Returns the result of mapping each element and combining the results.
@Terminates Applies f to a start value s and all elements in l going from right to left.
That is, the result is of the form: f(x1, ...f(xn-1, f(xn, s))...).
@Terminates Accumulates the result of applying f pairwise to the elements of l1 and l2
starting with the initial value c and going from right to left.
@Terminates @Tailrec Returns true if and only if all elements in l satisfy the predicate f.
Returns true if l is empty.
@Terminates @Tailrec Applies f to every element of l.
@Terminates Applies f to every element of l along with that element's index.
Returns the frequency for each element in list l
Returns the element at position i in the list l.
Throws IndexOutOfBoundsException if the index is out of bounds.
Partitions l into sublists such that for any two elements x and y in a sublist,
if f(x) and f(y) are equal according to Eq on b.
A sublist is created by iterating through the remaining elements of l from left to right and adding an
element to the sublist if and only if doing so creates no conflicts with the elements already in the sublist.
Partitions l into sublists such that for any two elements x and y in a sublist, f(x, y) is true.
A sublist is created by iterating through the remaining elements of l from left to right and adding an
element to the sublist if and only if doing so creates no conflicts with the elements already in the sublist.
The function f must be pure and define an equivalence relation.
@Terminates Returns Some(x) if x is the first element of l.
Returns None if l is empty.
@Terminates Optionally returns the position of x in l.
Returns the positions of all occurrences of x in l.
Returns the sublist of l without the last element.
Returns None if the list l is Nil.
Returns the concatenation of the elements in l2 with the elements of l1 inserted between every two adjacent elements.
That is, returns y1 :: x1 ... xn :: y2 :: ... yn-1 :: x1 :: ... :: xn :: yn :: Nil.
Returns l with x inserted between every two adjacent elements.
@Terminates Returns true if and only if l is the empty list, i.e. Nil.
@Terminates @Tailrec Returns true if and only if l1 is an infix of l2.
@Terminates @Tailrec Returns true if and only if l1 is a prefix of l2.
@Terminates Returns true if and only if l1 is a suffix of l2.
Build a list by applying f to the initial value x.
f should return Some(a1) to signal a new list element a1 (which also becomes the next input to f).
f should return None to signal the end of building the list.
Returns the concatenation of the string representation
of each element in l with sep inserted between each element.
Returns the concatenation of the string representation
of each element in l according to f with sep inserted between each element.
@Terminates @Tailrec Returns Some(x) if x is the last element of l.
Returns None if l is empty.
@Terminates Returns the result of applying f to every element in l.
That is, the result is of the form: f(x1) :: f(x2) :: ....
Lift a binary function to work on lists of its original arguments, returning a list
of applying all combinations of arguments.
For argument lists l1 = x1, x2, ... and l2 = y1, y2, ... the results appear in the order
f(x1,y1), f(x1,y2), ..., f(x2,y1), f(x2,y2), ....
def map3(f: t1 -> (t2 -> (t3 -> r \ ef)), l1: List[t1], l2: List[t2], l3: List[t3]): List[r] \ ef§ SourceLift a ternary function to work on lists of its original arguments, returning a list
of applying all combinations of arguments.
For argument lists l1 = x1, x2, ..., l2 = y1, y2, ... and l3 = z1, z2, ... the results appear
in the following order:
f(x1,y1,z1), f(x1,y1,z2), ..., f(x1,y2,z1), f(x1,y2,z2), ...,
f(x2,y1,z1), f(x2,y1,z2), ..., f(x2,y2,z1), f(x2,y2,z2), ...`
...
def map4(f: t1 -> (t2 -> (t3 -> (t4 -> r \ ef))), l1: List[t1], l2: List[t2], l3: List[t3], l4: List[t4]): List[r] \ ef§ SourceLift a 4-ary function to work on lists of its original arguments, returning a list
of applying all combinations of arguments. The results appear in the order extending the pattern from map3.
def map5(f: t1 -> (t2 -> (t3 -> (t4 -> (t5 -> r \ ef)))), l1: List[t1], l2: List[t2], l3: List[t3], l4: List[t4], l5: List[t5]): List[r] \ ef§ SourceLift a 5-ary function to work on lists of its original arguments, returning a list
of applying all combinations of arguments. The results appear in the order extending the pattern from map3.
@Terminates Returns the result of applying f to every element in l along with that element's index.
That is, the result is of the form: f(0, x0) :: f(1, x1) :: ....
Optionally finds the largest element of l according to the Order on a.
Returns None if l is empty.
Optionally finds the largest element of l according to the given comparator cmp.
Returns None if l is empty.
@Terminates @Tailrec Returns true if and only if l contains the element x.
@Terminates Merges the two lists l1 and l2. Assuming they are both sorted.
If two elements compare EqualTo, then the element of l1 is first in the result.
Optionally finds the smallest element of l according to the Order on a.
Returns None if l is empty.
Optionally finds the smallest element of l according to the given comparator cmp.
Returns None if l is empty.
@Terminates Returns true if and only if l is a non-empty list.
@Terminates Optionally returns the element at position i in the list l.
@Terminates Returns a pair of lists (l1, l2).
l1 contains all elements of l that satisfy the predicate f.
l2 contains all elements of l that do not satisfy the predicate f.
Returns l2 with the n elements starting at index i replaced with the elements of l1.
If any of the indices i, i+1, i+2, ... , i+n-1 are out of range in l2 then no patching is done at these indices.
If l1 becomes depleted then no further patching is done.
If patching occurs at index i+j in l2, then the element at index j in l1 is used.
Returns all permutations of l in lexicographical order by element indices in l.
That is, l is the first permutation and reverse(l) is the last permutation.
Returns a list of all integers between b (inclusive) and e (exclusive).
Returns Nil if b >= e.
@Terminates Applies f to all elements in l going from left to right until a single value v is obtained. Returns Some(v).
That is, the result is of the form: Some(f(...f(f(x1, x2), x3)..., xn))
Returns None if l is empty.
@Terminates Applies f to all elements in l going from right to left until a single value v is obtained. Returns Some(v).
That is, the result is of the form: Some(f(x1, ...f(xn-2, f(xn-1, xn))...))
Returns None if l is empty.
@Terminates Returns l without adjacent duplicates according to their Eq instance.
The first occurrence in a chain of duplicates is kept.
@Terminates Returns l without adjacent duplicates according to the function f.
Elements x and y are duplicates if and only if f(x, y) = true.
The first occurrence in a chain of duplicates is kept.
f must define an equivalence relation on the elements of the list.
Returns a list with the element x repeated n times.
Returns Nil if n < 0.
@Terminates Returns l with every occurrence of src replaced by dst.
Returns l with its elements rotated n positions to the left.
That is, returns a new list where the first n mod length(l) elements in l
are the last n mod length(l) elements of the new list.
Returns l with its elements rotated n positions to the right.
That is, returns a new list where the last n mod length(l) elements in l
are the first n mod length(l) elements of the new list.
@Terminates Alias for scanLeft.
@Terminates Accumulates the result of applying f to l going left to right.
That is, the result is of the form: s :: f(s, x1) :: f(f(s, x1), x2) ....
@Terminates Accumulates the result of applying f to l going right to left.
That is, the result is of the form: ... f(xn-1, f(xn, s)) :: f(xn, s) :: s.
def sequence(l: List[m[a]]): m[List[a]] with Applicative[m]§ SourceReturns the result of running all the actions in the list l going from left
to right.
@Terminates Returns the sublist of l from index start (inclusive) to index end (exclusive).
That is, an element at index i in l is part of the returned sublist if and only if i >= start and i < end.
Note: Indices that are out of bounds in l are not considered (i.e. slice(start, end, l) = slice(max(0, start), min(length(l), end), l)).
Sort list l so that elements are ordered from low to high according to their Order instance.
The sort is not stable, i.e., equal elements may appear in a different order than in the input l.
The sort implementation is a Quicksort.
Sort list l so that elements are ordered from low to high according to the Order instance
for the values obtained by applying f to each element.
The sort is not stable, i.e., equal elements may appear in a different order than in the input l.
The sort implementation is a Quicksort.
Sort list l so that elements are ordered from low to high according to the comparison function cmp.
The sort is not stable, i.e., equal elements may appear in a different order than in the input l.
The sort implementation is a Quicksort.
@Terminates Returns a pair of lists (l1, l2).
l1 is the longest prefix of l that satisfies the predicate f.
l2 is the remainder of l.
The function f must be pure.
@Terminates Split the list xs at the position n returning the left and right parts.
Position n is included in the right part.
Example: splitAt(2, 1::2::3::4::Nil) returns (1::2::Nil, 3::4::Nil)
Returns (xs, Nil) if n > length(xs).
Returns (Nil, xs) if n < 0.
Returns all subsequences of l in lexicographical order by element indices in l.
That is, l is the first subsequence and Nil is the last subsequence.
Returns the sum of all elements in the list l according to the function f.
@Terminates Returns the first n elements of l.
Returns l if n > length(l).
Returns Nil if n < 0.
@Terminates Returns the longest prefix of l that satisfies the predicate f.
Returns the association list l as a map.
If l contains multiple mappings with the same key the last occurrence is kept.
Returns a map with mappings k => v where (k, v) = f(x) for some x in l.
If multiple mappings with the same key are produced only the last occurrence is kept.
Returns the list l as Option[Nec[a]].
If l is empty return None, otherwise return the Nec wrapped in Some.
Returns the list l as Option[Nel[a]].
If l is empty return None, otherwise return the Nel wrapped in Some.
Returns the transpose of l.
Returns l if the dimensions of the elements of l are mismatched.
def traverse(f: a -> m[b] \ ef, l: List[a]): m[List[b]] \ ef with Applicative[m]§ SourceReturns the result of applying the applicative mapping function f to all the elements of the
list l going from left to right.
Build a list by applying f to the seed value st.
f should return Some(a,st1) to signal a new list element a and a new seed value st1.
f should return None to signal the end of building the list.
Build a list by applying the function next to (). next is expected to encapsulate
a stateful resource such as a file handle that can be iterated.
next should return Some(a) to signal a new list element a.
next should return None to signal the end of building the list.
Build a list by applying the function next to (). next is expected to encapsulate
a stateful resource such as a file handle that can be iterated.
next should return Ok(Some(a)) to signal a new list element Ok(a).
next should return Ok(None) to signal the end of building the list.
next should return Err(e) to signal that an error occurred. The function returns Err(e).
@Terminates Returns a pair of lists, the first containing all first components in l
and the second containing all second components in l.
@Terminates Returns a triple of lists, the first containing all first components in l
the second containing all second components in l and the third containing all
third components in l.
@Terminates Returns l with the element at index i replaced by x.
Returns l if i < 0 or i > length(l)-1.
@Terminates Returns a list where the element at index i is (a, b) where
a is the element at index i in l1 and b is the element at index i in l2.
If either l1 or l2 becomes depleted, then no further elements are added to the resulting list.
@Terminates Returns a list where the element at index i is (a, b, c) where
a is the element at index i in l1, b is the element at index i in l2
and c is the element at index i in l3.
If any one of l1, l2 or l3 become depleted, then no further elements are added to the resulting list.
@Terminates Returns a list where the element at index i is f(a, b) where
a is the element at index i in l1 and b is the element at index i in l2.
If either l1 or l2 becomes depleted, then no further elements are added to the resulting list.
@Terminates def zipWith3(f: a -> (b -> (c -> d \ ef)), l1: List[a], l2: List[b], l3: List[c]): List[d] \ ef§ SourceReturns a list where the element at index i is f(a, b, c) where
a is the element at index i in l1, b is the element at index i in l2
and c is the element at index i in l3.
If any one of l1, l2 or l3 become depleted, then no further elements are added to the resulting list.
def zipWithA(f: a -> (b -> f[c] \ ef), xs: List[a], ys: List[b]): f[List[c]] \ ef with Applicative[f]§ SourceGeneralize zipWith to an applicative functor f.