Extends the theory on functors, applicatives and monads.
A generalization of List.zipWith
which combines list elements with an Applicative
.
Like zipWithM
but evaluates the result as it traverses the lists using *>
.
Equations
- zipWithM' f (x_2 :: xs) (y :: ys) = SeqRight.seqRight (f x_2 y) fun x => zipWithM' f xs ys
- zipWithM' f [] x = pure PUnit.unit
- zipWithM' f x [] = pure PUnit.unit
A generalization of List.partition
which partitions the list according to a monadic
predicate. List.partition
corresponds to the case where f = Id
.
Equations
- List.partitionM p [] = pure ([], [])
- List.partitionM p (x_1 :: xs) = condM (p x_1) (Prod.map (List.cons x_1) id <$> List.partitionM p xs) (Prod.map id (List.cons x_1) <$> List.partitionM p xs)
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, [])
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, [])
Returns pure true
if the computation succeeds and pure false
otherwise.
Equations
- succeeds x = HOrElse.hOrElse (Functor.mapConst true x) fun x => pure false
Attempts to perform the computation, but fails silently if it doesn't succeed.
Equations
- tryM x = HOrElse.hOrElse (Functor.mapConst () x) fun x => pure ()
Computations performed first on
a : α
and then onb : β
are equal to those performed in the reverse order.
A CommApplicative
functor m
is a (lawful) applicative functor which behaves identically on
α × β× β
and β × α× α
, so computations can occur in either order.