DelayList
Definitions
def
ap
[aefb]
(
f :
DelayList[a -> b \ ef]
l :
DelayList[a]
)
: DelayList[b]
\ ef
Apply every function from f
to every argument from l
and return a list with all results.
For f = f1, f2, ...
and l = x1, x2, ...
the results appear in the order
f1(x1), f1(x2), ..., f2(x1), f2(x2), ...
.
Whether the i-th function in f
(fi
) is applied eagerly or lazily depends on its purity:
- If
fi
is pure then it is applied lazily (i.e. the tail ofl
is not forced). - If
fi
is impure then it is applied eagerly (i.e. the entire listl
is forced).
Note that this implies that ALL functions in f
must be pure to avoid forcing l
.
def
append
[a]
(
l1 :
DelayList[a]
l2 :
DelayList[a]
)
: DelayList[a]
\ Pure
Returns l2
appended to l1
.
Does not force the tail of l1
.
def
count
[aef]
(
f :
a -> Bool \ ef
l :
DelayList[a]
)
: Int32
\ ef
Returns the number of elements in l
that satisfy the predicate f
.
Forces the entire list l
.
def
drop
[a]
(
n :
Int32
l :
DelayList[a]
)
: DelayList[a]
\ Pure
Returns l
without the first n
elements.
Returns ENil
if n > length(l)
.
Returns l
if n < 1
.
Does not force the tail of l
.
def
dropWhile
[aef]
(
f :
a -> Bool \ ef
l :
DelayList[a]
)
: DelayList[a]
\ ef
Returns l
without the longest prefix that satisfies the predicate f
.
Whether f
is applied eagerly or lazily depends on its purity:
- If
f
is pure then it is applied lazily (i.e. the tail is not forced). - If
f
is impure then it is applied eagerly (i.e. the tail is forced until the first element that satisfiesf
).
def
enumerator
[ra]
(
rc :
Region[r]
l :
DelayList[a]
)
: Iterator[(Int32, a), r, r]
\ r
Returns an iterator over l
zipped with the indices of the elements.
def
exists
[aef]
(
f :
a -> Bool \ ef
l :
DelayList[a]
)
: Bool
\ ef
Returns true
if and only if at least one element in l
satisfies the predicate f
.
Returns false
if l
is empty.
Forces elements of l
until the predicate f
is satisfied.
def
filter
[aef]
(
f :
a -> Bool \ ef
l :
DelayList[a]
)
: DelayList[a]
\ ef
Returns a DelayList
with every element in l
that satisfies the predicate f
.
Whether f
is applied eagerly or lazily depends on its purity:
- If
f
is pure then it is applied lazily (i.e. the tail is not forced). - If
f
is impure then it is applied eagerly (i.e. the entire listl
is forced).
def
filterMap
[aefb]
(
f :
a -> Option[b] \ ef
l :
DelayList[a]
)
: DelayList[b]
\ ef
Collects the results of applying the partial function f
to every element in l
.
Whether f
is applied eagerly or lazily depends on its purity:
- If
f
is pure then it is applied lazily (i.e. the tail is not forced). - If
f
is impure then it is applied eagerly (i.e. the entire listl
is forced).
def
findLeft
[aef]
(
f :
a -> Bool \ ef
l :
DelayList[a]
)
: Option[a]
\ ef
Optionally returns the first element of l
that satisfies the predicate f
when searching from left to right.
Forces elements of l
until the predicate f
is satisfied.
def
findMap
[aefb]
(
f :
a -> Option[b] \ ef
l :
DelayList[a]
)
: Option[b]
\ ef
Returns the first non-None result of applying the partial function f
to each element of l
.
Returns None
if every element f(x)
of l
is None
.
Forces elements of l
until f(x)
returns Some(v)
.
def
findRight
[aef]
(
f :
a -> Bool \ ef
l :
DelayList[a]
)
: Option[a]
\ ef
Optionally returns the first element of l
that satisfies the predicate f
when searching from right to left.
Forces the entire list l
.
def
flatMap
[aefb]
(
f :
a -> DelayList[b] \ ef
l :
DelayList[a]
)
: DelayList[b]
\ ef
Returns the result of applying f
to every element in l
and concatenating the results.
Whether f
is applied eagerly or lazily depends on its purity:
- If
f
is pure then it is applied lazily (i.e. the tail is not forced). - If
f
is impure then it is applied eagerly (i.e. the entire listl
is forced).
def
flatten
[a]
(
l :
DelayList[DelayList[a]]
)
: DelayList[a]
\ Pure
Returns the concatenation of the elements in l
.
Does not force the tail of l
.
def
foldLeft
[baef]
(
f :
b -> (a -> b \ ef)
s :
b
l :
DelayList[a]
)
: b
\ ef
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)
.
Forces the entire list l
.
def
foldMap
[aefb]
(
f :
a -> b \ ef
l :
DelayList[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
l :
DelayList[a]
)
: b
\ ef
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))...)
.
Forces the entire list l
.
def
foldRightWithCont
[aefb]
(
f :
a -> ((Unit -> b \ ef) -> b \ ef)
z :
b
l :
DelayList[a]
)
: b
\ ef
Applies f
to a start value z
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, z))...)
.
A foldRightWithCont
allows early termination by not calling the continuation.
Calling the continuation forces the list l
.
def
forAll
[aef]
(
f :
a -> Bool \ ef
l :
DelayList[a]
)
: Bool
\ ef
Returns true
if and only if all elements in l
satisfy the predicate f
.
Returns true
if l
is empty.
Forces elements in l
until the first element that does not satisfy the predicate f
(inclusive).
def
forEach
[aef]
(
f :
a -> Unit \ ef
l :
DelayList[a]
)
: Unit
\ ef
Applies f
to every element of l
.
Forces the entire list l
.
def
forEachWithIndex
[aef]
(
f :
Int32 -> (a -> Unit \ ef)
l :
DelayList[a]
)
: Unit
\ ef
Applies f
to every element of l
along with that element's index.
Forces the entire list l
.
def
from
(
n :
Int32
)
: DelayList[Int32]
\ Pure
Returns an infinite sequence of integers starting from and including n
.
def
head
[a]
(
l :
DelayList[a]
)
: Option[a]
\ Pure
Returns Some(x)
if x
is the first element of l
.
Returns None
if l
is empty.
Does not force the tail of l
.
def
intercalate
[a]
(
l1 :
DelayList[a]
l2 :
DelayList[DelayList[a]]
)
: DelayList[a]
\ Pure
Returns the concatenation of the elements in l2
with the elements
of l1
inserted between every two adjacent elements of l2
.
That is, returns l2.1 :: l1.1 ... l1.n :: l2.2 :: ... :: l2.n-1 :: l1.1 :: ... :: l1.n :: l2.n :: ENil
.
Does not force the tail of l2
.
def
intersperse
[a]
(
x :
a
l :
DelayList[a]
)
: DelayList[a]
\ Pure
Returns l
with x
inserted between every two adjacent elements.
Does not force the tail of l
.
def
isEmpty
[a]
(
l :
DelayList[a]
)
: Bool
\ Pure
Returns true if and only if l
is the empty DelayList, i.e. ENil
.
Does not force the tail of l
.
def
iterator
[ra]
(
rc :
Region[r]
l :
DelayList[a]
)
: Iterator[a, r, r]
\ r
Returns l
as an Iterator
.
Does not force any elements of the list.
def
join
[a]
(
sep :
String
l :
DelayList[a]
)
: String
\ Pure
with
ToString[a]
Returns the concatenation of the string representation
of each element in l
with sep
inserted between each element.
Forces the entire list l
.
def
joinWith
[aef]
(
f :
a -> String \ ef
sep :
String
l :
DelayList[a]
)
: String
\ ef
Returns the concatenation of the string representation
of each element in l
according to f
with sep
inserted between each element.
Forces the entire list l
.
def
last
[a]
(
l :
DelayList[a]
)
: Option[a]
\ Pure
Returns Some(x)
if x
is the last element of l
.
Returns None
if l
is empty.
Forces the entire list l
.
def
length
[a]
(
l :
DelayList[a]
)
: Int32
\ Pure
Returns the length of l
.
Forces the entire list l
.
def
map
[aefb]
(
f :
a -> b \ ef
l :
DelayList[a]
)
: DelayList[b]
\ ef
Returns the result of applying f
to every element in l
.
Whether f
is applied eagerly or lazily depends on its purity:
- If
f
is pure then it is applied lazily (i.e. the tail is not forced). - If
f
is impure then it is applied eagerly (i.e. the entire listl
is forced).
def
mapWithIndex
[aefb]
(
f :
Int32 -> (a -> b \ ef)
l :
DelayList[a]
)
: DelayList[b]
\ ef
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(x1, 0) :: f(x2, 1) :: ...
.
Whether f
is applied eagerly or lazily depends on its purity:
- If
f
is pure then it is applied lazily (i.e. the tail is not forced). - If
f
is impure then it is applied eagerly (i.e. the entire listl
is forced).
def
maximum
[a]
(
l :
DelayList[a]
)
: Option[a]
\ Pure
with
Order[a]
Optionally finds the largest element of l
according to the Order
on a
.
Returns None
if l
is empty.
Forces the entire list l
.
def
maximumBy
[a]
(
cmp :
a -> (a -> Comparison)
l :
DelayList[a]
)
: Option[a]
\ Pure
Optionally finds the largest element of l
according to the given comparator cmp
.
Returns None
if l
is empty.
Forces the entire list l
.
def
memberOf
[a]
(
x :
a
l :
DelayList[a]
)
: Bool
\ Pure
with
Eq[a]
Returns true
if and only if l
contains the element x
.
Forces elements until x
is found.
def
minimum
[a]
(
l :
DelayList[a]
)
: Option[a]
\ Pure
with
Order[a]
Optionally finds the smallest element of l
according to the Order
on a
.
Returns None
if l
is empty.
Forces the entire list l
.
def
minimumBy
[a]
(
cmp :
a -> (a -> Comparison)
l :
DelayList[a]
)
: Option[a]
\ Pure
Optionally finds the smallest element of l
according to the given comparator cmp
.
Returns None
if l
is empty.
Forces the entire list l
.
def
partition
[aef]
(
f :
a -> Bool \ ef
l :
DelayList[a]
)
: (DelayList[a], DelayList[a])
\ ef
Returns a pair of lists (l1, l2)
where:
l1
contains all elements ofl
that satisfy the predicatef
.l2
contains all elements ofl
that DO NOT satisfy the predicatef
.
Forces the entire list l
.
def
range
(
b :
Int32
e :
Int32
)
: DelayList[Int32]
\ Pure
Returns a DelayList
of all integers between b
(inclusive) and e
(exclusive).
Returns an empty DelayList
if b >= e
.
def
reduceLeft
[aef]
(
f :
a -> (a -> a \ ef)
l :
DelayList[a]
)
: Option[a]
\ ef
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.
Forces the entire list l
.
def
reduceRight
[aef]
(
f :
a -> (a -> a \ ef)
l :
DelayList[a]
)
: Option[a]
\ ef
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.
Forces the entire list l
.
def
repeat
[a]
(
x :
a
)
: DelayList[a]
\ Pure
Returns an infinite DelayList of repeating x
s.
def
replace
[a]
(
from :
{ from = a }
to :
{ to = a }
l :
DelayList[a]
)
: DelayList[a]
\ Pure
with
Eq[a]
Returns l
with every occurrence of from
replaced by to
.
Does not force the tail of l
.
def
reverse
[a]
(
l :
DelayList[a]
)
: DelayList[a]
\ Pure
Reverses the list l
.
Does not force the tail of l
.
def
sequence
[ma]
(
l :
DelayList[m[a]]
)
: m[DelayList[a]]
\ Pure
with
Applicative[m]
Returns the result of running all the actions in the DelayList l
.
def
shuffle
[a]
(
rnd :
Random
l :
DelayList[a]
)
: DelayList[a]
\ IO
Shuffles l
using the Fisher–Yates shuffle.
def
singleton
[a]
(
x :
a
)
: DelayList[a]
\ Pure
Return the singleton list with element x
.
def
span
[aef]
(
f :
a -> Bool \ ef
l :
DelayList[a]
)
: (DelayList[a], DelayList[a])
\ ef
Returns a pair of lists (l1, l2)
where:
l1
is the longest prefix ofl
that satisfies the predicatef
.l2
is the remainder ofl
.
Whether f
is applied eagerly or lazily depends on its purity:
- If
f
is pure then it is applied lazily (i.e. the tail is not forced). - If
f
is impure then it is applied eagerly (i.e. the entire listl
is forced).
def
sum
(
l :
DelayList[Int32]
)
: Int32
\ Pure
Returns the sum of all elements in the DelayList l
.
Forces the entire list l
.
def
sumWith
[aef]
(
f :
a -> Int32 \ ef
l :
DelayList[a]
)
: Int32
\ ef
Returns the sum of all elements in the DelayList l
according to the function f
.
Forces the entire list l
.
def
tail
[a]
(
l :
DelayList[a]
)
: DelayList[a]
\ Pure
Returns l
without the first element.
Does not force the tail of l
.
def
take
[a]
(
n :
Int32
l :
DelayList[a]
)
: DelayList[a]
\ Pure
Returns the first n
elements of l
.
Does not force the tail of l
.
def
takeWhile
[aef]
(
f :
a -> Bool \ ef
l :
DelayList[a]
)
: DelayList[a]
\ ef
Returns the longest prefix of l
that satisfies the predicate f
.
Whether f
is applied eagerly or lazily depends on its purity:
- If
f
is pure then it is applied lazily (i.e. the tail is not forced). - If
f
is impure then it is applied eagerly (i.e. the tail is forced until the first element that satisfiesf
).
def
toArray
[ra]
(
rc :
Region[r]
l :
DelayList[a]
)
: Array[a, r]
\ r
Returns l
as an Array
.
Forces the entire list l
.
def
toList
[a]
(
l :
DelayList[a]
)
: List[a]
\ Pure
Returns l
as a List
.
Forces the entire list l
.
def
toMap
[ab]
(
l :
DelayList[(a, b)]
)
: Map[a, b]
\ Pure
with
Order[a]
Returns the association list l
as a map.
If l
contains multiple mappings with the same key, toMap
does not
make any guarantees about which mapping will be in the resulting map.
Forces the entire list l
.
def
toMutDeque
[ra]
(
rc :
Region[r]
l :
DelayList[a]
)
: MutDeque[a, r]
\ r
Returns l
as a MutDeque.
def
toMutList
[ra]
(
rc :
Region[r]
l :
DelayList[a]
)
: MutList[a, r]
\ r
Returns l
as a List
.
Forces the entire list l
.
def
toSet
[a]
(
l :
DelayList[a]
)
: Set[a]
\ Pure
with
Order[a]
Returns l
as a Set
.
Forces the entire list l
.
def
toString
[a]
(
l :
DelayList[a]
)
: String
\ Pure
with
ToString[a]
Returns a string representation of l
.
Forces the entire list l
.
def
toVector
[a]
(
l :
DelayList[a]
)
: Vector[a]
\ Pure
Returns l
as a Vector.
Forces the entire list l
.
def
traverse
[aefmb]
(
f :
a -> m[b] \ ef
l :
DelayList[a]
)
: m[DelayList[b]]
\ ef
with
Applicative[m]
Returns the result of applying the applicative mapping function f
to all the elements of the
DelayList l
.
def
zip
[ab]
(
l1 :
DelayList[a]
l2 :
DelayList[b]
)
: DelayList[(a, b)]
\ Pure
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
is depleted, then no further elements are added to the resulting list.
Does not force the tail of either l1
or l2
.
def
zipWith
[abefc]
(
f :
a -> (b -> c \ ef)
l1 :
DelayList[a]
l2 :
DelayList[b]
)
: DelayList[c]
\ ef
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
is depleted, then no further elements are added to the resulting list.
Whether f
is applied eagerly or lazily depends on its purity:
- If
f
is pure then it is applied lazily (i.e. the tails are not forced). - If
f
is impure then it is applied eagerly (i.e. both listsl1
andl2
are forced).
def
zipWithIndex
[a]
(
l :
DelayList[a]
)
: DelayList[(Int32, a)]
\ Pure
Returns a DelayList
where each element e
is mapped to (i, e)
where i
is the index of e
.
Does not force the tail of l
.