Module docstring
{}
{}
Option.instMembership
instance
: Membership α (Option α)
instance : Membership α (Option α) := ⟨fun b a => b = some a⟩
Option.mem_def
theorem
{a : α} {b : Option α} : a ∈ b ↔ b = some a
@[simp] theorem mem_def {a : α} {b : Option α} : a ∈ ba ∈ b ↔ b = some a := .rfl
Option.instDecidableMemOfDecidableEq
instance
[DecidableEq α] (j : α) (o : Option α) : Decidable (j ∈ o)
instance [DecidableEq α] (j : α) (o : Option α) : Decidable (j ∈ o) :=
inferInstanceAs <| Decidable (o = some j)
Option.isNone_iff_eq_none
theorem
{o : Option α} : o.isNone ↔ o = none
@[simp] theorem isNone_iff_eq_none {o : Option α} : o.isNone ↔ o = none :=
⟨Option.eq_none_of_isNone, fun e => e.symm ▸ rfl⟩
Option.some_inj
theorem
{a b : α} : some a = some b ↔ a = b
theorem some_inj {a b : α} : somesome a = some b ↔ a = b := by simp; rfl
Option.decidable_eq_none
definition
{o : Option α} : Decidable (o = none)
/--
Equality with `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 the standard instance of
`DecidableEq (Option α)`, which can cause problems. It can be locally bound if needed.
Try to use the Boolean comparisons `Option.isNone` or `Option.isSome` instead.
-/
@[inline] def decidable_eq_none {o : Option α} : Decidable (o = none) :=
decidable_of_decidable_of_iff isNone_iff_eq_none
Option.instDecidableForallForallMemOfDecidablePred
instance
{p : α → Prop} [DecidablePred p] : ∀ o : Option α, Decidable (∀ a, a ∈ o → p a)
Option.instDecidableExistsAndMemOfDecidablePred
instance
{p : α → Prop} [DecidablePred p] : ∀ o : Option α, Decidable (Exists fun a => a ∈ o ∧ p a)
instance {p : α → Prop} [DecidablePred p] : ∀ o : Option α, Decidable (Exists fun a => a ∈ oa ∈ o ∧ p a)
| none => isFalse nofun
| some a => if h : p a then isTrue ⟨_, rfl, h⟩ else isFalse fun ⟨_, ⟨rfl, hn⟩⟩ => h hn
Option.pbind
definition
: (o : Option α) → (f : (a : α) → a ∈ o → Option β) → Option β
/--
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 `a ∈ o`, which
is equivalent to `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:
```lean example
def attach (v : Option α) : Option { y : α // y ∈ v } :=
v.pbind fun x h => some ⟨x, h⟩
```
```lean example
#reduce attach (some 3)
```
```output
some ⟨3, ⋯⟩
```
```lean example
#reduce attach none
```
```output
none
```
-/
@[inline]
def pbind : (o : Option α) → (f : (a : α) → a ∈ o → Option β) → Option β
| none, _ => none
| some a, f => f a rfl
Option.pmap
definition
{p : α → Prop} (f : ∀ a : α, p a → β) : (o : Option α) → (∀ a, a ∈ o → p a) → Option β
/--
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:
```lean example
def attach (v : Option α) : Option { y : α // y ∈ v } :=
v.pmap (fun a (h : a ∈ v) => ⟨_, h⟩) (fun _ h => h)
```
```lean example
#reduce attach (some 3)
```
```output
some ⟨3, ⋯⟩
```
```lean example
#reduce attach none
```
```output
none
```
-/
@[inline] def pmap {p : α → Prop}
(f : ∀ a : α, p a → β) :
(o : Option α) → (∀ a, a ∈ o → p a) → Option β
| none, _ => none
| some a, H => f a (H a rfl)
Option.pelim
definition
(o : Option α) (b : β) (f : (a : α) → a ∈ o → β) : β
/--
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 `a ∈ o`, which
is equivalent to `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:
```lean example
def attach (v : Option α) : Option { y : α // y ∈ v } :=
v.pelim none fun x h => some ⟨x, h⟩
```
```lean example
#reduce attach (some 3)
```
```output
some ⟨3, ⋯⟩
```
```lean example
#reduce attach none
```
```output
none
```
-/
@[inline] def pelim (o : Option α) (b : β) (f : (a : α) → a ∈ o → β) : β :=
match o with
| none => b
| some a => f a rfl
Option.forM
definition
[Pure m] : Option α → (α → m PUnit) → m PUnit
/--
Executes a monadic action on an optional value if it is present, or does nothing if there is no
value.
Examples:
```lean example
#eval ((some 5).forM set : StateM Nat Unit).run 0
```
```output
((), 5)
```
```lean example
#eval (none.forM (fun x : Nat => set x) : StateM Nat Unit).run 0
```
```output
((), 0)
```
-/
@[inline] protected def forM [Pure m] : Option α → (α → m PUnit) → m PUnit
| none , _ => pure ⟨⟩
| some a, f => f a
Option.instForM
instance
: ForM m (Option α) α
instance : ForM m (Option α) α :=
⟨Option.forM⟩
Option.instForIn'InferInstanceMembership
instance
: ForIn' m (Option α) α inferInstance
instance : ForIn' m (Option α) α inferInstance where
forIn' x init f := do
match x with
| none => return init
| some a =>
match ← f a rfl init with
| .done r | .yield r => return r