Chain
Enums
Definitions
def
ap
[aefb]
(
f :
Chain[a -> b \ ef]
x :
Chain[a]
)
: Chain[b]
\ ef
Apply every function from f
to every argument from x
and return a chain 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), ...
.
def
append
[a]
(
c1 :
Chain[a]
c2 :
Chain[a]
)
: Chain[a]
\ Pure
Returns a new chain formed by appending the chains c1
and c2
.
def
compare
[a]
(
c1 :
Chain[a]
c2 :
Chain[a]
)
: Comparison
\ Pure
with
Order[a]
Compares chains c1
and c2
lexicographically.
def
cons
[a]
(
x :
a
c :
Chain[a]
)
: Chain[a]
\ Pure
Add element x
to the left end of chain c
.
def
count
[aef]
(
f :
a -> Bool \ ef
c :
Chain[a]
)
: Int32
\ ef
Returns the number of elements in c
that satisfy the predicate f
.
def
dropLeft
[a]
(
n :
Int32
c :
Chain[a]
)
: Chain[a]
\ Pure
Returns c
without the first n
elements.
Returns Nil
if n > length(c)
.
Returns c
if n < 0
.
def
dropRight
[a]
(
n :
Int32
c :
Chain[a]
)
: Chain[a]
\ Pure
Returns c
without the last n
elements.
Returns Nil
if n > length(c)
.
Returns c
if n < 0
.
def
dropWhileLeft
[aef]
(
f :
a -> Bool \ ef
c :
Chain[a]
)
: Chain[a]
\ ef
Returns c
without the longest prefix that satisfies the predicate f
.
def
dropWhileRight
[aef]
(
f :
a -> Bool \ ef
c :
Chain[a]
)
: Chain[a]
\ ef
Returns c
without the longest suffix that satisfies the predicate f
.
def
empty
[a]
: Chain[a]
\ Pure
Return the empty chain.
def
enumerator
[ra]
(
rc :
Region[r]
c :
Chain[a]
)
: Iterator[(Int32, a), r, r]
\ r
Returns an iterator over c
zipped with the indices of the elements.
def
equals
[a]
(
c1 :
Chain[a]
c2 :
Chain[a]
)
: Bool
\ Pure
with
Eq[a]
Returns true
if and only if c1
and c2
and equal.
def
exists
[aef]
(
f :
a -> Bool \ ef
c :
Chain[a]
)
: Bool
\ ef
Returns true
if and only if at least one element in c
satisfies the predicate f
.
Returns false
if c
is empty.
def
filter
[aef]
(
f :
a -> Bool \ ef
c :
Chain[a]
)
: Chain[a]
\ ef
Returns a list of every element in c
that satisfies the predicate f
.
The function f
must be pure.
def
filterMap
[aefb]
(
f :
a -> Option[b] \ ef
c :
Chain[a]
)
: Chain[b]
\ ef
Collects the results of applying the partial function f
to every element in c
.
def
find
[a]
(
f :
a -> Bool
c :
Chain[a]
)
: Option[a]
\ Pure
Alias for findLeft
.
The function f
must be pure.
def
findLeft
[a]
(
f :
a -> Bool
c :
Chain[a]
)
: Option[a]
\ Pure
Optionally returns the first element of c
that satisfies the predicate f
when searching from left to right.
The function f
must be pure.
def
findMap
[aefb]
(
f :
a -> Option[b] \ ef
c :
Chain[a]
)
: Option[b]
\ ef
Returns the first non-None result of applying the partial function f
to each element of c
.
Returns None
if every element of c
is None
.
def
findRight
[a]
(
f :
a -> Bool
c :
Chain[a]
)
: Option[a]
\ Pure
Optionally returns the first element of c
that satisfies the predicate f
when searching from right to left.
The function f
must be pure.
def
flatMap
[aefb]
(
f :
a -> Chain[b] \ ef
c :
Chain[a]
)
: Chain[b]
\ ef
Returns the result of applying f
to every element in c
and concatenating the results.
def
flatten
[a]
(
c :
Chain[Chain[a]]
)
: Chain[a]
\ Pure
Returns the concatenation of the elements in c
.
def
foldLeft
[baef]
(
f :
b -> (a -> b \ ef)
s :
b
c :
Chain[a]
)
: b
\ ef
Applies f
to a start value s
and all elements in c
going from left to right.
That is, the result is of the form: f(...f(f(s, x1), x2)..., xn)
.
def
foldMap
[aefb]
(
f :
a -> b \ ef
c :
Chain[a]
)
: b
\ ef
with
Monoid[b]
Returns the result of mapping each element and combining the results.
def
foldRight
[abef]
(
f :
a -> (b -> b \ ef)
s :
b
c :
Chain[a]
)
: b
\ ef
Applies f
to a start value s
and all elements in c
going from right to left.
That is, the result is of the form: f(x1, ...f(xn-1, f(xn, s))...)
.
def
foldRightWithCont
[aefb]
(
f :
a -> ((Unit -> b \ ef) -> b \ ef)
z :
b
c :
Chain[a]
)
: b
\ ef
Applies f
to a start value z
and all elements in c
going from right to left.
That is, the result is of the form: f(x1, ...f(xn-1, f(xn, z))...)
.
A foldRightWithCont
allows early termination by not calling the continuation.
def
forAll
[aef]
(
f :
a -> Bool \ ef
c :
Chain[a]
)
: Bool
\ ef
Returns true
if and only if all elements in c
satisfy the predicate f
.
Returns true
if c
is empty.
def
forEach
[aef]
(
f :
a -> Unit \ ef
c :
Chain[a]
)
: Unit
\ ef
Applies f
to every element of c
.
def
forEachWithIndex
[aef]
(
f :
Int32 -> (a -> Unit \ ef)
c :
Chain[a]
)
: Unit
\ ef
Applies f
to every element of c
along with that element's index.
def
head
[a]
(
c :
Chain[a]
)
: Option[a]
\ Pure
Returns Some(x)
if x
is the first element of c
.
Returns None
if c
is empty.
def
indexOf
[a]
(
a :
a
c :
Chain[a]
)
: Option[Int32]
\ Pure
with
Eq[a]
Optionally returns the position of a
in c
.
def
init
[a]
(
c :
Chain[a]
)
: Option[Chain[a]]
\ Pure
Returns the subchain of c
without the last element.
Returns None
if the chain c
is empty.
def
intersperse
[a]
(
a :
a
c :
Chain[a]
)
: Chain[a]
\ Pure
Returns c
with a
inserted between every two adjacent elements.
def
isEmpty
[a]
(
c :
Chain[a]
)
: Bool
\ Pure
Returns true if and only if c
is the empty chain.
def
iterator
[ra]
(
rc :
Region[r]
c :
Chain[a]
)
: Iterator[a, r, r]
\ r
Returns an iterator over c
.
def
join
[a]
(
sep :
String
c :
Chain[a]
)
: String
\ Pure
with
ToString[a]
Returns the concatenation of the string representation
of each element in c
with sep
inserted between each element.
def
joinWith
[aef]
(
f :
a -> String \ ef
sep :
String
c :
Chain[a]
)
: String
\ ef
Returns the concatenation of the string representation
of each element in c
according to f
with sep
inserted between each element.
def
last
[a]
(
c :
Chain[a]
)
: Option[a]
\ Pure
Returns Some(x)
if x
is the last element of c
.
Returns None
if c
is empty.
def
length
[a]
(
c :
Chain[a]
)
: Int32
\ Pure
Returns the length of c
.
def
map
[aefb]
(
f :
a -> b \ ef
c :
Chain[a]
)
: Chain[b]
\ ef
Returns the result of applying f
to every element in c
.
That is, the result is of the form: f(x1) :: f(x2) :: ...
.
def
mapAccumLeft
[saefb]
(
f :
s -> (a -> (s, b) \ ef)
start :
s
c :
Chain[a]
)
: (s, Chain[b])
\ ef
mapAccumLeft
is a stateful version of map
. The accumulating paramter s
is updated at each
step in a left-to-right traversal.
def
mapAccumRight
[saefb]
(
f :
s -> (a -> (s, b) \ ef)
start :
s
c :
Chain[a]
)
: (s, Chain[b])
\ ef
mapAccumRight
is a stateful version of map
. The accumulating parameter s
is updated at each
step in a right-to-left traversal.
def
mapWithIndex
[aefb]
(
f :
Int32 -> (a -> b \ ef)
c :
Chain[a]
)
: Chain[b]
\ ef
Returns the result of applying f
to every element in c
along with that element's index.
That is, the result is of the form: f(x1, 0) :: f(x2, 1) :: ...
.
def
memberOf
[a]
(
a :
a
c :
Chain[a]
)
: Bool
\ Pure
with
Eq[a]
Returns true
if and only if c
contains the element a
.
def
range
(
b :
Int32
e :
Int32
)
: Chain[Int32]
\ Pure
Returns a list of all integers between b
(inclusive) and e
(exclusive).
Returns Nil
if b >= e
.
def
repeat
[a]
(
n :
Int32
a :
a
)
: Chain[a]
\ Pure
Returns a list with the element a
repeated n
times.
Returns Nil
if n < 0
.
def
reverse
[a]
(
c :
Chain[a]
)
: Chain[a]
\ Pure
Returns the reverse of c
.
def
scan
[baef]
(
f :
b -> (a -> b \ ef)
s :
b
c :
Chain[a]
)
: Chain[b]
\ ef
Alias for scanLeft
.
def
scanLeft
[baef]
(
f :
b -> (a -> b \ ef)
s :
b
c :
Chain[a]
)
: Chain[b]
\ ef
Accumulates the result of applying f
to c
going left to right.
That is, the result is of the form: s :: f(s, x1) :: f(f(s, x1), x2) ...
.
def
scanRight
[abef]
(
f :
a -> (b -> b \ ef)
s :
b
c :
Chain[a]
)
: Chain[b]
\ ef
Accumulates the result of applying f
to c
going right to left.
That is, the result is of the form: ... f(xn-1, f(xn, s)) :: f(xn, s) :: s
.
def
sequence
[ma]
(
c :
Chain[m[a]]
)
: m[Chain[a]]
\ Pure
with
Applicative[m]
Returns the result of running all the actions in the chain c
.
def
shuffle
[a]
(
rnd :
Random
c :
Chain[a]
)
: Chain[a]
\ IO
Shuffles c
using the Fisher–Yates shuffle.
def
singleton
[a]
(
x :
a
)
: Chain[a]
\ Pure
Return the singleton chain with element x
.
def
snoc
[a]
(
c :
Chain[a]
x :
a
)
: Chain[a]
\ Pure
Add element x
to the right end of chain c
.
def
sort
[a]
(
c :
Chain[a]
)
: Chain[a]
\ Pure
with
Order[a]
Sort chain c
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 c
.
The sort implementation is a Quicksort.
def
sortBy
[ab]
(
f :
a -> b
c :
Chain[a]
)
: Chain[a]
\ Pure
with
Order[b]
Sort chain c
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 c
.
The sort implementation is a Quicksort.
def
sortWith
[a]
(
cmp :
a -> (a -> Comparison)
c :
Chain[a]
)
: Chain[a]
\ Pure
Sort chain c
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 c
.
The sort implementation is a Quicksort.
def
sum
(
c :
Chain[Int32]
)
: Int32
\ Pure
Returns the sum of all elements in the chain c
.
def
sumWith
[aef]
(
f :
a -> Int32 \ ef
c :
Chain[a]
)
: Int32
\ ef
Returns the sum of all elements in the chain c
according to the function f
.
def
takeLeft
[a]
(
n :
Int32
c :
Chain[a]
)
: Chain[a]
\ Pure
Returns the first n
elements of c
.
Returns c
if n > length(c)
.
Returns Nil
if n < 0
.
def
takeRight
[a]
(
n :
Int32
c :
Chain[a]
)
: Chain[a]
\ Pure
Returns the last n
elements of c
.
Returns c
if n > length(c)
.
Returns Nil
if n < 0
.
def
takeWhileLeft
[aef]
(
f :
a -> Bool \ ef
c :
Chain[a]
)
: Chain[a]
\ ef
Returns the longest prefix of c
that satisfies the predicate f
.
def
takeWhileRight
[aef]
(
f :
a -> Bool \ ef
c :
Chain[a]
)
: Chain[a]
\ ef
Returns the longest suffix of c
that satisfies the predicate f
.
def
toArray
[ra]
(
rc :
Region[r]
c :
Chain[a]
)
: Array[a, r]
\ r
Returns the chain c
as an array.
def
toList
[a]
(
c :
Chain[a]
)
: List[a]
\ Pure
Returns c
as a list.
def
toMap
[ab]
(
c :
Chain[(a, b)]
)
: Map[a, b]
\ Pure
with
Order[a]
Returns the chain of pairs c
that represents an association list as a map.
If c
contains multiple mappings with the same key, toMap
does not
make any guarantees about which mapping will be in the resulting map.
def
toMutDeque
[ra]
(
rc :
Region[r]
c :
Chain[a]
)
: MutDeque[a, r]
\ r
Returns c
as a MutDeque.
def
toMutList
[ra]
(
rc :
Region[r]
c :
Chain[a]
)
: MutList[a, r]
\ r
Returns c
as a mutable list.
def
toNec
[a]
(
c :
Chain[a]
)
: Option[Nec[a]]
\ Pure
Returns the chain c
as a Nec.
def
toNel
[a]
(
c :
Chain[a]
)
: Option[Nel[a]]
\ Pure
Returns the chain c
as a Nel.
def
toSet
[a]
(
c :
Chain[a]
)
: Set[a]
\ Pure
with
Order[a]
Returns the list c
as a set.
def
toVector
[a]
(
c :
Chain[a]
)
: Vector[a]
\ Pure
Returns the chain c
as a vector.
def
traverse
[aefmb]
(
f :
a -> m[b] \ ef
c :
Chain[a]
)
: m[Chain[b]]
\ ef
with
Applicative[m]
Returns the result of applying the applicative mapping function f
to all the elements of the
chain c
.
def
unzip
[ab]
(
c :
Chain[(a, b)]
)
: (Chain[a], Chain[b])
\ Pure
Returns a pair of chains, the first containing all first components in c
and the second containing all second components in c
.
def
viewLeft
[a]
(
c :
Chain[a]
)
: ViewLeft[a]
\ Pure
Deconstruct a Chain from left-to-right.
Returns ViewLeft(x, rs)
if the chain is non-empty, where x
is the leftmost
element of the chain c
, and rs
is the rest of the chain.
Returns ViewLeft.NoneLeft
if the chain is empty.
def
viewRight
[a]
(
c :
Chain[a]
)
: ViewRight[a]
\ Pure
Deconstruct a Chain from right-to-left.
Returns ViewRight(rs, x)
if the chain is non-empty, where x
is the rightmost
element of the chain c``, and
rs` is the front of the chain.
Returns ViewRight.NoneRight
if the chain is empty.
def
zip
[ab]
(
c1 :
Chain[a]
c2 :
Chain[b]
)
: Chain[(a, b)]
\ Pure
Returns a chain where the element at index i
is (a, b)
where
a
is the element at index i
in c1
and b
is the element at index i
in c2
.
If either c1
or c2
becomes depleted, then no further elements are added to the resulting chain.
def
zipWith
[abefc]
(
f :
a -> (b -> c \ ef)
c1 :
Chain[a]
c2 :
Chain[b]
)
: Chain[c]
\ ef
Returns a chain where the element at index i
is f(a, b)
where
a
is the element at index i
in c1
and b
is the element at index i
in c2
.
If either c1
or c2
becomes depleted, then no further elements are added to the resulting chain.
def
zipWithA
[abefmc]
(
f :
a -> (b -> m[c] \ ef)
xs :
Chain[a]
ys :
Chain[b]
)
: m[Chain[c]]
\ ef
with
Applicative[m]
Generalize zipWith
to an applicative functor f
.
def
zipWithIndex
[a]
(
c :
Chain[a]
)
: Chain[(Int32, a)]
\ Pure
Returns a chain where each element e
is mapped to (i, e)
where i
is the index of e
.