Extra definitions on option
#
This file defines more operations involving option α
. Lemmas about them are located in other
files under data.option.
.
Other basic operations on option
are defined in the core library.
o = none
is decidable even if the wrapped type does not have decidable equality.
This is not an instance because it is not definitionally equal to option.decidable_eq
.
Try to use o.is_none
or o.is_some
instead.
filter p o
returns some a
if o
is some a
and p a
holds, otherwise none
.
Equations
- option.filter p o = o.bind (option.guard p)
Two arguments failsafe function. Returns f a b
if the inputs are some a
and some b
, and
"does nothing" otherwise.
Equations
- option.lift_or_get f (some a) (some b) = some (f a b)
- option.lift_or_get f (some a) none = some a
- option.lift_or_get f none (some b) = some b
- option.lift_or_get f none none = none
- some : ∀ {α : Type u_1} {β : Type u_2} {r : α → β → Prop} {a : α} {b : β}, r a b → option.rel r (some a) (some b)
- none : ∀ {α : Type u_1} {β : Type u_2} {r : α → β → Prop}, option.rel r none none
Lifts a relation α → β → Prop
to a relation option α → option β → Prop
by just adding
none ~ none
.
Partial bind. If for some x : option α
, f : Π (a : α), a ∈ x → option β
is a
partial function defined on a : α
giving an option β
, where some a = x
,
then pbind x f h
is essentially the same as bind x f
but is defined only when all x = some a
, using the proof to apply f
.
Partial map. If f : Π a, p a → β
is a partial function defined on a : α
satisfying p
,
then pmap f x h
is essentially the same as map f x
but is defined only when all members of x
satisfy p
, using the proof to apply f
.
Equations
- option.pmap f (some a) H = some (f a _)
- option.pmap f none _x = none
Equations
- option.traverse f (some x) = some <$> f x
- option.traverse f none = pure none
If you maybe have a monadic computation in a [monad m]
which produces a term of type α
, then
there is a naturally associated way to always perform a computation in m
which maybe produces a
result.
Map a monadic function f : α → m β
over an o : option α
, maybe producing a result.
Equations
- option.mmap f o = (option.map f o).maybe
A monadic analogue of option.elim
.
Equations
- option.melim x y z = x >>= λ (o : option α), o.elim y z
A monadic analogue of option.get_or_else
.
Equations
- option.mget_or_else x y = option.melim x y pure