Extends the theory on functors, applicatives and monads.
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}
{F : Type u → Type v}
[Applicative F]
[LawfulApplicative F]
(x : F (α → β))
(f : γ → α)
(y : F γ)
:
def
List.mapAccumRM
{α : Type u}
{β' γ' : 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}
{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}
(f : α → β)
(a : m (m α))
:
@[simp]
@[simp]
@[simp]
A CommApplicative
functor m
is a (lawful) applicative functor which behaves identically on
α × β
and β × α
, so computations can occur in either order.
- map_const : ∀ {α β : Type u}, Functor.mapConst = Functor.map ∘ Function.const β
- seqLeft_eq : ∀ {α β : Type u} (x : m α) (y : m β), x <* y = Function.const β <$> x <*> y
- seqRight_eq : ∀ {α β : Type u} (x : m α) (y : m β), x *> y = Function.const α id <$> x <*> y
- commutative_prod : ∀ {α β : Type u} (a : m α) (b : m β), Prod.mk <$> a <*> b = (fun (b : β) (a : α) => (a, b)) <$> b <*> a
Computations performed first on
a : α
and then onb : β
are equal to those performed in the reverse order.
Instances
theorem
CommApplicative.commutative_map
{m : Type u → Type v}
[h : Applicative m]
[CommApplicative m]
{α β γ : Type u}
(a : m α)
(b : m β)
{f : α → β → γ}
: