Set
Definitions
@ParallelWhenPure
def count(f: a -> Bool \ ef, s: Set[a]): Int32 \ ef
SourceReturns the number of elements in s
that satisfy the predicate f
.
Purity reflective: Runs in parallel when given a pure function f
.
def difference(s1: Set[a], s2: Set[a]): Set[a]
SourceReturns the difference of s1
and s2
, i.e. s1 - s2
.
def empty(_unit: Unit): Set[a]
SourceReturns the empty set.
Set#{}
is syntactic sugar for empty
i.e. Set#{} == empty()
.
def enumerator(rc: Region[r], s: Set[a]): Iterator[(Int32, a), r, r] \ r
SourceReturns an iterator over s
zipped with the indices of the elements.
def exists(f: a -> Bool \ ef, s: Set[a]): Bool \ ef
SourceReturns true
if and only if at least one element in s
satisfies the predicate f
.
Returns false
if s
is the empty set.
def filter(f: a -> Bool \ ef, s: Set[a]): Set[a] \ ef
SourceReturns the set of all elements of s
that satisfy the predicate f
.
def filterMap(f: a -> Option[b] \ ef, s: Set[a]): Set[b] \ ef
SourceCollects the results of applying the partial function f
to every element in s
.
def findLeft(f: a -> Bool \ ef, s: Set[a]): Option[a] \ ef
SourceOptionally returns the first element of s
that satisfies the predicate f
when searching from left to right.
def findRight(f: a -> Bool \ ef, s: Set[a]): Option[a] \ ef
SourceOptionally returns the first element of s
that satisfies the predicate f
when searching from right to left.
def flatMap(f: a -> Set[b] \ ef, s: Set[a]): Set[b] \ ef
SourceReturns the result of applying f
to every element in s
and taking the union.
def fold(s: Set[a]): a
SourceReturns the result of applying combine
to all the elements in s
, using empty
as the initial value.
def foldLeft(f: b -> (a -> b \ ef), s: b, s1: Set[a]): b \ ef
SourceApplies f
to a start value s
and all elements in s
going from left to right.
That is, the result is of the form: f(...f(f(s, x1), x2)..., xn)
.
def foldMap(f: a -> b \ ef, s: Set[a]): b \ ef
SourceReturns the result of mapping each element and combining the results.
def foldRight(f: a -> (b -> b \ ef), s: b, s1: Set[a]): b \ ef
SourceApplies f
to a start value s
and all elements in s1
going from right to left.
That is, the result is of the form: f(x1, ...f(xn-1, f(xn, s))...)
.
def foldRightWithCont(f: a -> ((Unit -> b \ ef) -> b \ ef), z: b, s: Set[a]): b \ ef
SourceApplies f
to a start value z
and all elements in s
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(f: a -> Bool \ ef, s: Set[a]): Bool \ ef
SourceReturns true
if and only if all elements in s
satisfy the predicate f
.
Returns true
if s
is the empty set.
def forEachWithIndex(f: Int32 -> (a -> Unit \ ef), s: Set[a]): Unit \ ef
SourceApplies f
to every element of s
along with that element's index.
def isProperSubsetOf(s1: Set[a], s2: Set[a]): Bool
SourceReturns true if and only if every element in s1
appears in s2
and s != s2
.
def isSubsetOf(s1: Set[a], s2: Set[a]): Bool
SourceReturns true if and only if every element in s1
appears in s2
.
def join(sep: String, s: Set[a]): String
SourceReturns the concatenation of the string representation
of each element in s
with sep
inserted between each element.
def joinWith(f: a -> String \ ef, sep: String, s: Set[a]): String \ ef
SourceReturns the concatenation of the string representation
of each element in s
according to f
with sep
inserted between each element.
def map(f: a -> b \ ef, s: Set[a]): Set[b] \ ef
SourceReturns the result of applying f
to every element in s
.
Note: The returned set may be smaller than s
.
def maximum(s: Set[a]): Option[a]
SourceOptionally finds the largest element of s
according to the Order
on a
.
Returns None
if s
is empty.
@ParallelWhenPure
def maximumBy(cmp: a -> (a -> Comparison \ ef), s: Set[a]): Option[a] \ ef
SourceOptionally finds the largest element of s
according to the given comparator cmp
.
Returns None
if s
is empty.
Purity reflective: Runs in parallel when given a pure function f
.
def minimum(s: Set[a]): Option[a]
SourceOptionally finds the smallest element of s
according to the Order
on a
.
Returns None
if s
is empty.
@ParallelWhenPure
def minimumBy(cmp: a -> (a -> Comparison \ ef), s: Set[a]): Option[a] \ ef
SourceOptionally finds the smallest element of s
according to the given comparator cmp
.
Returns None
if s
is empty.
Purity reflective: Runs in parallel when given a pure function f
.
def partition(f: a -> Bool \ ef, s: Set[a]): (Set[a], Set[a]) \ ef
SourceReturns a pair of sets (s1, s2)
.
s1
contains all elements of s
that satisfy the predicate f
.
s2
contains all elements of s
that do not satisfy the predicate f
.
def range(b: Int32, e: Int32): Set[Int32]
SourceReturns a set of all integers between b
(inclusive) and e
(exclusive).
Returns empty()
if b >= e
.
def reduceLeft(f: a -> (a -> a \ ef), s: Set[a]): Option[a] \ ef
SourceApplies f
to all elements in s
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 s
is the empty set.
def reduceRight(f: a -> (a -> a \ ef), s: Set[a]): Option[a] \ ef
SourceApplies f
to all elements in s
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 s
is the empty set.
def replace(from: { from = a }, to: { to = a }, s: Set[a]): Set[a]
SourceReplaces the element from
with to
if from
is in s
. Otherwise, returns s
.
Note: The returned set may be smaller than s
.
def singleton(x: a): Set[a]
SourceReturns the singleton set containing x
.
Set#{x}
is syntactic sugar for singleton
i.e. Set#{x} == singleton(x)
.
@ParallelWhenPure
def sumWith(f: a -> Int32 \ ef, s: Set[a]): Int32 \ ef
SourceReturns the sum of all elements in the set s
according to the function f
.
Purity reflective: Runs in parallel when given a pure function f
.
def toMap(s: Set[(a, b)]): Map[a, b]
SourceReturns the association set s
as a map.
If s
contains multiple mappings with the same key, toMap
does not
make any guarantees about which mapping will be in the resulting map.
def toMapWith(f: a -> b, s: Set[a]): Map[a, b]
SourceReturns a map with elements of s
as keys and f
applied as values.
def unfold(f: s -> Option[(a, s)] \ ef, st: s): Set[a] \ ef
SourceBuild a set by applying f
to the seed value st
.
f
should return Some(a,st1)
to signal a new set element a
and a new seed value st1
.
f
should return None
to signal the end of building the set.
def unfoldWithIter(next: Unit -> Option[a] \ ef): Set[a] \ ef
SourceBuild a set 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 value pair a
.
next
should return None
to signal the end of building the set.