Extends the theory on functors, applicatives and monads.
def
zipWithM
{F : Type u → Type v}
[Applicative F]
{α₁ : Type u}
{α₂ : Type u}
{φ : Type u}
(f : α₁ → α₂ → F φ)
:
A generalization of List.zipWith
which combines list elements with an Applicative
.
Equations
Instances For
@[simp]
theorem
pure_id'_seq
{α : Type u}
{F : Type u → Type v}
[Applicative F]
[LawfulApplicative F]
(x : F α)
:
theorem
seq_map_assoc
{α : Type u}
{β : Type u}
{γ : Type u}
{F : Type u → Type v}
[Applicative F]
[LawfulApplicative F]
(x : F (α → β))
(f : γ → α)
(y : F γ)
:
def
List.mapAccumRM
{α : Type u}
{β' : Type v}
{γ' : Type v}
{m' : Type v → Type w}
[Monad m']
(f : α → β' → m' (β' × γ'))
:
Takes a value β
and List α
and accumulates pairs according to a monadic function f
.
Accumulation occurs from the right (i.e., starting from the tail of the list).
Equations
- One or more equations did not get rendered due to their size.
- List.mapAccumRM f x [] = pure (x, [])
Instances For
def
List.mapAccumLM
{α : Type u}
{β' : Type v}
{γ' : Type v}
{m' : Type v → Type w}
[Monad m']
(f : β' → α → m' (β' × γ'))
:
Takes a value β
and List α
and accumulates pairs according to a monadic function f
.
Accumulation occurs from the left (i.e., starting from the head of the list).
Equations
- One or more equations did not get rendered due to their size.
- List.mapAccumLM f x [] = pure (x, [])
Instances For
theorem
joinM_map_map
{m : Type u → Type u}
[Monad m]
[LawfulMonad m]
{α : Type u}
{β : Type u}
(f : α → β)
(a : m (m α))
:
@[simp]
@[simp]
@[simp]
class
CommApplicative
(m : Type u → Type v)
[Applicative m]
extends
LawfulApplicative
,
LawfulFunctor
:
A CommApplicative
functor m
is a (lawful) applicative functor which behaves identically on
α × β
and β × α
, so computations can occur in either order.
Instances
theorem
CommApplicative.commutative_prod
{m : Type u → Type v}
:
∀ {inst : Applicative m} [self : CommApplicative m] {α β : Type u} (a : m α) (b : m β),
Prod.mk <$> a <*> b = (fun (b : β) (a : α) => (a, b)) <$> b <*> a
Computations performed first on a : α
and then on b : β
are equal to those performed in
the reverse order.
theorem
CommApplicative.commutative_map
{m : Type u → Type v}
[h : Applicative m]
[CommApplicative m]
{α : Type u}
{β : Type u}
{γ : Type u}
(a : m α)
(b : m β)
{f : α → β → γ}
: