Map a function over an EStateM.Result, preserving states and errors.
Equations
- EStateM.Result.map f (EStateM.Result.ok a s') = EStateM.Result.ok (f a) s'
- EStateM.Result.map f (EStateM.Result.error e s') = EStateM.Result.error e s'
Instances For
@[simp]
@[simp]
@[simp]
theorem EStateM.run_seq {ε σ α β : Type u_1} (f : EStateM ε σ (α → β)) (x : EStateM ε σ α) (s : σ) :
(f <*> x).run s = match f.run s with
| Result.ok g s => Result.map g (x.run s)
| Result.error e s => Result.error e s
theorem EStateM.run'_seq {ε σ α β : Type u_1} (f : EStateM ε σ (α → β)) (x : EStateM ε σ α) (s : σ) :
(f <*> x).run' s = match f.run s with
| Result.ok g s => Option.map g (x.run' s)
| Result.error a a_1 => none
@[simp]
theorem EStateM.run_seqLeft {ε σ α β : Type u_1} (x : EStateM ε σ α) (y : EStateM ε σ β) (s : σ) :
(x <* y).run s = match x.run s with
| Result.ok v s => Result.map (fun (x : β) => v) (y.run s)
| Result.error e s => Result.error e s
@[simp]
theorem EStateM.run'_seqLeft {ε σ α β : Type u_1} (x : EStateM ε σ α) (y : EStateM ε σ β) (s : σ) :
(x <* y).run' s = match x.run s with
| Result.ok v s => Option.map (fun (x : β) => v) (y.run' s)
| Result.error a a_1 => none
@[simp]
theorem EStateM.run_seqRight {ε σ α β : Type u_1} (x : EStateM ε σ α) (y : EStateM ε σ β) (s : σ) :
(x *> y).run s = match x.run s with
| Result.ok a s => y.run s
| Result.error e s => Result.error e s
@[simp]
@[simp]
theorem EStateM.run_orElse {σ ε α δ : Type u_1} [h : Backtrackable δ σ] (x₁ x₂ : EStateM ε σ α) (s : σ) :
(x₁ <|> x₂).run s = match x₁.run s with
| Result.ok x s => Result.ok x s
| Result.error a s' => x₂.run (Backtrackable.restore s' (Backtrackable.save s))
@[simp]
theorem EStateM.run'_orElse {σ ε α δ : Type u_1} [h : Backtrackable δ σ] (x₁ x₂ : EStateM ε σ α) (s : σ) :
(x₁ <|> x₂).run' s = match x₁.run s with
| Result.ok x a => some x
| Result.error a s' => x₂.run' (Backtrackable.restore s' (Backtrackable.save s))
@[simp]
theorem EStateM.run_tryCatch {σ ε α δ : Type u_1} [h : Backtrackable δ σ] (body : EStateM ε σ α) (handler : ε → EStateM ε σ α) (s : σ) :
(tryCatch body handler).run s = match body.run s with
| Result.ok x s => Result.ok x s
| Result.error e s' => (handler e).run (Backtrackable.restore s' (Backtrackable.save s))
@[simp]
theorem EStateM.run'_tryCatch {σ ε α δ : Type u_1} [h : Backtrackable δ σ] (body : EStateM ε σ α) (handler : ε → EStateM ε σ α) (s : σ) :
(tryCatch body handler).run' s = match body.run s with
| Result.ok x a => some x
| Result.error e s' => (handler e).run' (Backtrackable.restore s' (Backtrackable.save s))
@[simp]
@[simp]
theorem EStateM.run_tryFinally' {ε σ α β : Type u_1} (x : EStateM ε σ α) (h : Option α → EStateM ε σ β) (s : σ) :
(tryFinally' x h).run s = match x.run s with
| Result.ok a s =>
match (h (some a)).run s with
| Result.ok b s => Result.ok (a, b) s
| Result.error e s => Result.error e s
| Result.error e₁ s =>
match (h none).run s with
| Result.ok a s => Result.error e₁ s
| Result.error e₂ s => Result.error e₂ s
@[simp]
theorem EStateM.run'_tryFinally' {ε σ α β : Type u_1} (x : EStateM ε σ α) (h : Option α → EStateM ε σ β) (s : σ) :
(tryFinally' x h).run' s = match x.run s with
| Result.ok a s => Option.map (fun (x : β) => (a, x)) ((h (some a)).run' s)
| Result.error a a_1 => none
@[simp]
@[simp]