Option
Definitions
def
ap
[aefb]
(
f :
Option[a -> b \ ef]
x :
Option[a]
)
: Option[b]
\ ef
If both arguments are Some
, return a Some
containing the result of applying the function inside
f
to the value inside x
. Otherwise return None
.
def
count
[aef]
(
f :
a -> Bool \ ef
o :
Option[a]
)
: Int32
\ ef
Returns 1
if o
is Some(v)
and the predicate f(v)
evaluates to true
. Otherwise returns 0
.
def
enumerator
[ra]
(
rc :
Region[r]
o :
Option[a]
)
: Iterator[(Int32, a), r, r]
\ r
Returns an iterator over o
zipped with the indices of the elements.
def
exists
[aef]
(
f :
a -> Bool \ ef
o :
Option[a]
)
: Bool
\ ef
Returns true
if o
is Some(v)
and the predicate f(v)
evaluates to true
. Otherwise returns false
.
def
filter
[aef]
(
f :
a -> Bool \ ef
o :
Option[a]
)
: Option[a]
\ ef
Returns o
if o
is Some(v)
and the predicate f(v)
is true. Otherwise returns None
.
def
find
[a]
(
f :
a -> Bool
o :
Option[a]
)
: Option[a]
\ Pure
Returns o
if o
is Some(v)
and the predicate f(v)
evaluates to true
. Otherwise returns None
.
The function f
must be pure.
def
flatMap
[aefb]
(
f :
a -> Option[b] \ ef
o :
Option[a]
)
: Option[b]
\ ef
Returns f(v)
if o
is Some(v)
. Otherwise returns None
.
def
flatten
[a]
(
o :
Option[Option[a]]
)
: Option[a]
\ Pure
Returns v
if o
is Some(v)
. Otherwise returns None
.
def
fold
[a]
(
o :
Option[a]
)
: a
\ Pure
with
Monoid[a]
Returns the result of applying combine
to all the elements in o
, using empty
as the initial value.
def
foldLeft
[baef]
(
f :
b -> (a -> b \ ef)
z :
b
o :
Option[a]
)
: b
\ ef
Returns f(z, v)
if o
is Some(v)
. Otherwise returns z
.
def
foldLeftM
[baef]
(
f :
b -> (a -> Option[b] \ ef)
s :
b
l :
List[a]
)
: Option[b]
\ ef
Returns the result of applying f
to a start value s
and the elements in l
going from left to right.
If at any step applying f
fails (i.e. it produces a None
value) the traversal
of l
is short-circuited and None
is returned.
If f
is successfully applied to all the elements in l
the result is of the form:
Some(f(...f(f(s, x1), x2)..., xn))
.
def
foldMap
[aefb]
(
f :
a -> b \ ef
o :
Option[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)
o :
Option[a]
z :
b
)
: b
\ ef
Returns f(v, z)
if o
is Some(v)
. Otherwise returns z
.
def
foldRightM
[abef]
(
f :
a -> (b -> Option[b] \ ef)
s :
b
l :
List[a]
)
: Option[b]
\ ef
Returns the result of applying f
to a start value s
and the elements in l
going from right to left.
If at any step applying f
fails (i.e. it produces a None
value) the traversal
of l
is short-circuited and None
is returned.
If f
is successfully applied to al elements in l
the result is of the form:
Some(f(x1, ...f(xn-1, f(xn, s))...))
.
def
foldRightWithCont
[aefb]
(
f :
a -> ((Unit -> b \ ef) -> b \ ef)
o :
Option[a]
z :
b
)
: b
\ ef
Returns f(v, z)
if o
is Some(v)
. Otherwise returns z
.
A foldRightWithCont
allows early termination by not calling the continuation.
def
forAll
[aef]
(
f :
a -> Bool \ ef
o :
Option[a]
)
: Bool
\ ef
Returns true
if o
is Some(v)
and the predicate f(v)
evaluates to true
or if o
is None
.
Otherwise returns false
.
def
forEach
[aef]
(
f :
a -> Unit \ ef
o :
Option[a]
)
: Unit
\ ef
Applies f
to v
if o
is Some(v)
. Otherwise does nothing.
def
getWithDefault
[a]
(
d :
a
o :
Option[a]
)
: a
\ Pure
Returns v
if o
is Some(v).
Otherwise returns d
.
def
isEmpty
[a]
(
o :
Option[a]
)
: Bool
\ Pure
Returns true
iff o
is None
.
def
iterator
[ra]
(
rc :
Region[r]
o :
Option[a]
)
: Iterator[a, r, r]
\ r
Returns an iterator over o
with 1 element or an empty iterator if o
is None
.
def
map
[aefb]
(
f :
a -> b \ ef
o :
Option[a]
)
: Option[b]
\ ef
Returns Some(f(v))
if o
is Some(v)
. Otherwise returns None
.
def
map10
[t1t2t3t4t5t6t7t8t9t10efu]
(
f :
t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> (t9 -> (t10 -> u \ ef)))))))))
o1 :
Option[t1]
o2 :
Option[t2]
o3 :
Option[t3]
o4 :
Option[t4]
o5 :
Option[t5]
o6 :
Option[t6]
o7 :
Option[t7]
o8 :
Option[t8]
o9 :
Option[t9]
o10 :
Option[t10]
)
: Option[u]
\ ef
Applies the 10-ary function f
to the values in o1
, o2
, ... o10
.
Returns None
if any of o1
, o2
, ... o10
are None
.
def
map2
[t1t2efu]
(
f :
t1 -> (t2 -> u \ ef)
o1 :
Option[t1]
o2 :
Option[t2]
)
: Option[u]
\ ef
Applies the binary function f
to the values in o1
and o2
.
Returns None
if either o1
or o2
are None
.
def
map3
[t1t2t3efu]
(
f :
t1 -> (t2 -> (t3 -> u \ ef))
o1 :
Option[t1]
o2 :
Option[t2]
o3 :
Option[t3]
)
: Option[u]
\ ef
Applies the ternary function f
to the values in o1
, o2
and o3
.
Returns None
if any of o1
, o2
and o3
are None
.
def
map4
[t1t2t3t4efu]
(
f :
t1 -> (t2 -> (t3 -> (t4 -> u \ ef)))
o1 :
Option[t1]
o2 :
Option[t2]
o3 :
Option[t3]
o4 :
Option[t4]
)
: Option[u]
\ ef
Applies the 4-ary function f
to the values in o1
, o2
, o3
and o4
.
Returns None
if any of o1
, o2
, o3
and o4
are None
.
def
map5
[t1t2t3t4t5efu]
(
f :
t1 -> (t2 -> (t3 -> (t4 -> (t5 -> u \ ef))))
o1 :
Option[t1]
o2 :
Option[t2]
o3 :
Option[t3]
o4 :
Option[t4]
o5 :
Option[t5]
)
: Option[u]
\ ef
Applies the 5-ary function f
to the values in o1
, o2
, ... o5
.
Returns None
if any of o1
, o2
, ... o5
are None
.
def
map6
[t1t2t3t4t5t6efu]
(
f :
t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> u \ ef)))))
o1 :
Option[t1]
o2 :
Option[t2]
o3 :
Option[t3]
o4 :
Option[t4]
o5 :
Option[t5]
o6 :
Option[t6]
)
: Option[u]
\ ef
Applies the 6-ary function f
to the values in o1
, o2
, ... o6
.
Returns None
if any of o1
, o2
, ... o6
are None
.
def
map7
[t1t2t3t4t5t6t7efu]
(
f :
t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> u \ ef))))))
o1 :
Option[t1]
o2 :
Option[t2]
o3 :
Option[t3]
o4 :
Option[t4]
o5 :
Option[t5]
o6 :
Option[t6]
o7 :
Option[t7]
)
: Option[u]
\ ef
Applies the 7-ary function f
to the values in o1
, o2
, ... o7
.
Returns None
if any of o1
, o2
, ... o7
are None
.
def
map8
[t1t2t3t4t5t6t7t8efu]
(
f :
t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> u \ ef)))))))
o1 :
Option[t1]
o2 :
Option[t2]
o3 :
Option[t3]
o4 :
Option[t4]
o5 :
Option[t5]
o6 :
Option[t6]
o7 :
Option[t7]
o8 :
Option[t8]
)
: Option[u]
\ ef
Applies the 8-ary function f
to the values in o1
, o2
, ... o8
.
Returns None
if any of o1
, o2
, ... o8
are None
.
def
map9
[t1t2t3t4t5t6t7t8t9efu]
(
f :
t1 -> (t2 -> (t3 -> (t4 -> (t5 -> (t6 -> (t7 -> (t8 -> (t9 -> u \ ef))))))))
o1 :
Option[t1]
o2 :
Option[t2]
o3 :
Option[t3]
o4 :
Option[t4]
o5 :
Option[t5]
o6 :
Option[t6]
o7 :
Option[t7]
o8 :
Option[t8]
o9 :
Option[t9]
)
: Option[u]
\ ef
Applies the 9-ary function f
to the values in o1
, o2
, ... o9
.
Returns None
if any of o1
, o2
, ... o9
are None
.
def
point
[a]
(
x :
a
)
: Option[a]
\ Pure
Returns Some(x)
.
def
replace
[a]
(
from :
{ from = a }
to :
{ to = a }
o :
Option[a]
)
: Option[a]
\ Pure
with
Eq[a]
Returns Some(to)
if o
is Some(from)
. Otherwise returns o
.
def
sequence
[a]
(
l :
List[Option[a]]
)
: Option[List[a]]
\ Pure
Returns Some(v1 :: v2 :: ... :: vn)
if each of xs_i
is Some(v_i)
. Otherwise returns None
.
def
sum
(
o :
Option[Int32]
)
: Int32
\ Pure
Returns v
if o
is Some(v)
else 0
.
def
sumWith
[aef]
(
f :
a -> Int32 \ ef
o :
Option[a]
)
: Int32
\ ef
Returns f(v)
if o
is Some(v)
else 0
.
def
toErr
[te]
(
d :
t
o :
Option[e]
)
: Result[e, t]
\ Pure
Returns the Option value Err(e)
if o
is Some(e)
. Otherwise returns Ok(d)
.
def
toFailure
[te]
(
d :
t
o :
Option[e]
)
: Validation[e, t]
\ Pure
Returns e
into Validation's Failure
if o
is Some(e)
. Otherwise returns Success(d)
.
def
toList
[a]
(
o :
Option[a]
)
: List[a]
\ Pure
Returns a one-element list of the value v
if o
is Some(v)
. Otherwise returns the empty list.
def
toMap
[kv]
(
o :
Option[(k, v)]
)
: Map[k, v]
\ Pure
with
Order[k]
Returns a singleton map with the mapping k -> v
if o
is Some((k, v))
. Otherwise returns the empty map.
def
toMapWith
[ab]
(
f :
a -> b
s :
Option[a]
)
: Map[a, b]
\ Pure
with
Order[a]
Returns a map with elements of s
as keys and f
applied as values.
def
toOk
[et]
(
e :
e
o :
Option[t]
)
: Result[e, t]
\ Pure
Returns the Option value Ok(v)
if o
is Some(v)
. Otherwise returns Err(e)
.
def
toSet
[a]
(
o :
Option[a]
)
: Set[a]
\ Pure
with
Order[a]
Returns a one-element set of the value v
if o
is Some(v)
. Otherwise returns the empty set.
def
toSuccess
[et]
(
e :
e
o :
Option[t]
)
: Validation[e, t]
\ Pure
Returns the Validation value Success(v)
if o
is Some(v)
. Otherwise lifts e
into Validation's Failure
.
def
traverse
[aefb]
(
f :
a -> Option[b] \ ef
l :
List[a]
)
: Option[List[b]]
\ ef
Returns Some(v1 :: v2 :: ... v :: vn)
if each of f(l_i)
is Some(v_i)
. Otherwise returns None
.
def
traverseX
[aefb]
(
f :
a -> Option[b] \ ef
l :
List[a]
)
: Option[Unit]
\ ef
Returns Some()
if each of f(l_i)
is Some(_)
. Otherwise returns None
.
This function is the "forgetful" version of traverse
, use it when the you want the effect
of applying f
to each element but do not care about collecting the results.
def
unzip
[ab]
(
o :
Option[(a, b)]
)
: (Option[a], Option[b])
\ Pure
Returns (Some(v1), Some(v2))
if o
is Some((v1, v2))
. Otherwise returns (None, None)
.
def
withDefault
[a]
(
default :
{ default = Option[a] }
o :
Option[a]
)
: Option[a]
\ Pure
Returns o
if it is Some(v)
. Otherwise returns default
.
def
zip
[ab]
(
o1 :
Option[a]
o2 :
Option[b]
)
: Option[(a, b)]
\ Pure
Returns Some((v1, v2))
if o1
is Some(v1)
and o2
is Some(v2)
. Otherwise returns None
.