Extra definitions on option
#
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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.
An elimination principle for option
. It is a nondependent version of option.rec
.
Equations
- option.elim b f (option.some a) = f a
- option.elim b f option.none = b
Equations
- option.has_mem = {mem := λ (a : α) (b : option α), b = option.some a}
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.
Equations
- (option.some a).decidable_forall_mem = dite (p a) (λ (h : p a), decidable.is_true _) (λ (h : ¬p a), decidable.is_false _)
- option.none.decidable_forall_mem = decidable.is_true option.decidable_forall_mem._main._proof_1
Equations
- (option.some a).decidable_exists_mem = dite (p a) (λ (h : p a), decidable.is_true _) (λ (h : ¬p a), decidable.is_false _)
- option.none.decidable_exists_mem = decidable.is_false option.decidable_exists_mem._main._proof_1
Inhabited get
function. Returns a
if the input is some a
, otherwise returns default
.
Equations
guard p a
returns some a
if p a
holds, otherwise none
.
Equations
- option.guard p a = ite (p a) (option.some a) option.none
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 (option.some a) (option.some b) = option.some (f a b)
- option.lift_or_get f (option.some a) option.none = option.some a
- option.lift_or_get f option.none (option.some b) = option.some b
- option.lift_or_get f option.none option.none = option.none
Instances for option.lift_or_get
- some : ∀ {α : Type u_1} {β : Type u_2} {r : α → β → Prop} {a : α} {b : β}, r a b → option.rel r (option.some a) (option.some b)
- none : ∀ {α : Type u_1} {β : Type u_2} {r : α → β → Prop}, option.rel r option.none option.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
.
Equations
- (option.some a).pbind f = f a _
- option.none.pbind _x = option.none
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 (option.some a) H = option.some (f a _)
- option.pmap f option.none _x = option.none
Equations
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.
Equations
- (option.some fn).maybe = option.some <$> fn
- option.none.maybe = return option.none
A monadic analogue of option.elim
.
Equations
- option.melim y z x = x >>= option.elim y z
A monadic analogue of option.get_or_else
.