@[inline]
Equations
- Except.map f x = match x with | Except.error err => Except.error err | Except.ok v => Except.ok (f v)
Instances For
@[inline]
Equations
- Except.mapError f x = match x with | Except.error err => Except.error (f err) | Except.ok v => Except.ok v
Instances For
@[inline]
def
Except.bind
{ε : Type u}
{α : Type u_1}
{β : Type u_2}
(ma : Except ε α)
(f : α → Except ε β)
:
Except ε β
Equations
- Except.bind ma f = match ma with | Except.error err => Except.error err | Except.ok v => f v
Instances For
@[inline]
Returns true if the value is Except.ok
, false otherwise.
Equations
- Except.toBool x = match x with | Except.ok a => true | Except.error a => false
Instances For
@[inline]
Equations
- Except.toOption x = match x with | Except.ok a => some a | Except.error a => none
Instances For
@[inline]
def
Except.tryCatch
{ε : Type u}
{α : Type u_1}
(ma : Except ε α)
(handle : ε → Except ε α)
:
Except ε α
Equations
- Except.tryCatch ma handle = match ma with | Except.ok a => Except.ok a | Except.error e => handle e
Instances For
def
Except.orElseLazy
{ε : Type u}
{α : Type u_1}
(x : Except ε α)
(y : Unit → Except ε α)
:
Except ε α
Equations
- Except.orElseLazy x y = match x with | Except.ok a => Except.ok a | Except.error a => y ()
Instances For
@[inline]
def
ExceptT.bindCont
{ε : Type u}
{m : Type u → Type v}
[Monad m]
{α : Type u}
{β : Type u}
(f : α → ExceptT ε m β)
:
Equations
- ExceptT.bindCont f x = match x with | Except.ok a => f a | Except.error e => pure (Except.error e)
Instances For
@[inline]
def
ExceptT.bind
{ε : Type u}
{m : Type u → Type v}
[Monad m]
{α : Type u}
{β : Type u}
(ma : ExceptT ε m α)
(f : α → ExceptT ε m β)
:
ExceptT ε m β
Equations
- ExceptT.bind ma f = ExceptT.mk (ma >>= ExceptT.bindCont f)
Instances For
@[inline]
def
ExceptT.map
{ε : Type u}
{m : Type u → Type v}
[Monad m]
{α : Type u}
{β : Type u}
(f : α → β)
(x : ExceptT ε m α)
:
ExceptT ε m β
Equations
- ExceptT.map f x = ExceptT.mk do let a ← x match a with | Except.ok a => pure (Except.ok (f a)) | Except.error e => pure (Except.error e)
Instances For
@[inline]
def
ExceptT.tryCatch
{ε : Type u}
{m : Type u → Type v}
[Monad m]
{α : Type u}
(ma : ExceptT ε m α)
(handle : ε → ExceptT ε m α)
:
ExceptT ε m α
Equations
- ExceptT.tryCatch ma handle = ExceptT.mk do let res ← ma match res with | Except.ok a => pure (Except.ok a) | Except.error e => handle e
Instances For
instance
ExceptT.instMonadFunctorExceptT
{ε : Type u}
{m : Type u → Type v}
:
MonadFunctor m (ExceptT ε m)
@[inline]
def
ExceptT.adapt
{ε : Type u}
{m : Type u → Type v}
[Monad m]
{ε' : Type u}
{α : Type u}
(f : ε → ε')
:
Equations
- ExceptT.adapt f x = ExceptT.mk (Except.mapError f <$> x)
Instances For
@[always_inline]
instance
instMonadExceptOfExceptT
(m : Type u → Type v)
(ε₁ : Type u)
(ε₂ : Type u)
[Monad m]
[MonadExceptOf ε₁ m]
:
MonadExceptOf ε₁ (ExceptT ε₂ m)
Equations
- instMonadExceptOfExceptT m ε₁ ε₂ = { throw := fun {α} e => ExceptT.mk (throwThe ε₁ e), tryCatch := fun {α} x handle => ExceptT.mk (tryCatchThe ε₁ x handle) }
@[always_inline]
instance
instMonadExceptOfExceptT_1
(m : Type u → Type v)
(ε : Type u)
[Monad m]
:
MonadExceptOf ε (ExceptT ε m)
Equations
- instMonadExceptOfExceptT_1 m ε = { throw := fun {α} e => ExceptT.mk (pure (Except.error e)), tryCatch := fun {α} => ExceptT.tryCatch }
Equations
- instMonadExceptOfExcept ε = { throw := fun {α} => Except.error, tryCatch := fun {α} => Except.tryCatch }
@[inline]
def
MonadExcept.orelse'
{ε : Type u}
{m : Type v → Type w}
[MonadExcept ε m]
{α : Type v}
(t₁ : m α)
(t₂ : m α)
(useFirstEx : optParam Bool true)
:
m α
Alternative orelse operator that allows to select which exception should be used.
The default is to use the first exception since the standard orelse
uses the second.
Equations
Instances For
def
liftExcept
{ε : Type u_1}
{m : Type u_2 → Type u_3}
{α : Type u_2}
[MonadExceptOf ε m]
[Pure m]
:
Except ε α → m α
Equations
- liftExcept x = match x with | Except.ok a => pure a | Except.error e => throw e
Instances For
instance
instMonadControlExceptT
(ε : Type u)
(m : Type u → Type v)
[Monad m]
:
MonadControl m (ExceptT ε m)
Equations
- instMonadControlExceptT ε m = { stM := Except ε, liftWith := fun {α} f => liftM (f fun {β} x => ExceptT.run x), restoreM := fun {α} x => x }
tryFinally' x f
runsx
and then the "finally" computationf
. Whenx
succeeds witha : α
,f (some a)
is returned. Ifx
fails form
's definition of failure,f none
is returned. HencetryFinally'
can be thought of as performing the same role as afinally
block in an imperative programming language.
Instances
@[inline]
def
tryFinally
{m : Type u → Type v}
{α : Type u}
{β : Type u}
[MonadFinally m]
[Functor m]
(x : m α)
(finalizer : m β)
:
m α
Execute x
and then execute finalizer
even if x
threw an exception
Equations
- tryFinally x finalizer = let y := tryFinally' x fun x => finalizer; (fun x => x.fst) <$> y
Instances For
@[always_inline]
Equations
- Id.finally = { tryFinally' := fun {α β} x h => let a := x; let b := h (some x); pure (a, b) }
@[always_inline]
instance
ExceptT.finally
{m : Type u → Type v}
{ε : Type u}
[MonadFinally m]
[Monad m]
:
MonadFinally (ExceptT ε m)
Equations
- One or more equations did not get rendered due to their size.