Equations
- Option.instDecidableMemOfDecidableEq j o = inferInstanceAs (Decidable (o = some j))
Equations
- none.decidableForallMem = isTrue ⋯
- (some a).decidableForallMem = if h : p a then isTrue ⋯ else isFalse ⋯
Given an optional value and a function that can be applied when the value is some, returns the
result of applying the function if this is possible.
The function f is partial because it is only defined for the values a : α such that
o = some a. This restriction allows the function to use the fact that it can only be called when
o is not none: it can relate its argument to the optional value o. Its runtime behavior is
equivalent to that of Option.bind.
Examples:
def attach (v : Option α) : Option { y : α // v = some y } :=
v.pbind fun x h => some ⟨x, h⟩
#reduce attach (some 3)
some ⟨3, ⋯⟩
#reduce attach none
none
Instances For
Given a function from the elements of α that satisfy p to β and a proof that an optional value
satisfies p if it's present, applies the function to the value.
Examples:
def attach (v : Option α) : Option { y : α // v = some y } :=
v.pmap (fun a (h : a ∈ v) => ⟨_, h⟩) (fun _ h => h)
#reduce attach (some 3)
some ⟨3, ⋯⟩
#reduce attach none
none
Equations
- Option.pmap f none x_2 = none
- Option.pmap f (some a) H = some (f a ⋯)
Instances For
Given an optional value and a function that can be applied when the value is some, returns the
result of applying the function if this is possible, or a fallback value otherwise.
The function f is partial because it is only defined for the values a : α such that
o = some a. This restriction allows the function to use the fact that it can only be called when
o is not none: it can relate its argument to the optional value o. Its runtime behavior is
equivalent to that of Option.elim.
Examples:
def attach (v : Option α) : Option { y : α // v = some y } :=
v.pelim none fun x h => some ⟨x, h⟩
#reduce attach (some 3)
some ⟨3, ⋯⟩
#reduce attach none
none
Instances For
Executes a monadic action on an optional value if it is present, or does nothing if there is no value.
Examples:
#eval ((some 5).forM set : StateM Nat Unit).run 0
((), 5)
#eval (none.forM (fun x : Nat => set x) : StateM Nat Unit).run 0
((), 0)
Instances For
Equations
- Option.instForMOfMonad = { forM := Option.forM }
Equations
- One or more equations did not get rendered due to their size.