@[specialize]
def
List.forA
{m : Type u → Type v}
[inst : Applicative m]
{α : Type w}
(as : List α)
(f : α → m PUnit)
:
m PUnit
Equations
- List.forA [] f = pure PUnit.unit
- List.forA (a :: as_1) f = SeqRight.seqRight (f a) fun x => List.forA as_1 f
@[specialize]
Equations
- List.filterAuxM f [] x = pure x
- List.filterAuxM f (h :: t) x = do let b ← f h List.filterAuxM f t (cond b (h :: x) x)
@[inline]
def
List.filterM
{m : Type → Type v}
[inst : Monad m]
{α : Type}
(f : α → m Bool)
(as : List α)
:
m (List α)
Equations
- List.filterM f as = do let as ← List.filterAuxM f as [] pure (List.reverse as)
@[inline]
def
List.filterRevM
{m : Type → Type v}
[inst : Monad m]
{α : Type}
(f : α → m Bool)
(as : List α)
:
m (List α)
Equations
- List.filterRevM f as = List.filterAuxM f (List.reverse as) []
@[inline]
def
List.filterMapM
{m : Type u → Type v}
[inst : Monad m]
{α : Type u}
{β : Type u}
(f : α → m (Option β))
(as : List α)
:
m (List β)
Equations
- List.filterMapM f as = (fun loop => loop (List.reverse as) []) (List.filterMapM.loop f)
@[specialize]
def
List.filterMapM.loop
{m : Type u → Type v}
[inst : Monad m]
{α : Type u}
{β : Type u}
(f : α → m (Option β))
:
Equations
- List.filterMapM.loop f [] x = pure x
- List.filterMapM.loop f (a :: as) x = do let a ← f a match a with | none => List.filterMapM.loop f as x | some b => List.filterMapM.loop f as (b :: x)
@[specialize]
def
List.foldlM
{m : Type u → Type v}
[inst : Monad m]
{s : Type u}
{α : Type w}
(f : s → α → m s)
(init : s)
:
List α → m s
Equations
- List.foldlM x x [] = pure x
- List.foldlM x x (a :: as) = do let s' ← x x a List.foldlM x s' as
@[specialize]
def
List.foldrM
{m : Type u → Type v}
[inst : Monad m]
{s : Type u}
{α : Type w}
(f : α → s → m s)
(init : s)
:
List α → m s
Equations
- List.foldrM x x [] = pure x
- List.foldrM x x (a :: as) = do let s' ← List.foldrM x x as x a s'
@[specialize]
def
List.firstM
{m : Type u → Type v}
[inst : Monad m]
[inst : Alternative m]
{α : Type w}
{β : Type u}
(f : α → m β)
:
List α → m β
Equations
- List.firstM f [] = failure
- List.firstM f (a :: as) = HOrElse.hOrElse (f a) fun x => List.firstM f as
@[specialize]
Equations
- List.findM? p [] = pure none
- List.findM? p (a :: as) = do let a ← p a match a with | true => pure (some a) | false => List.findM? p as
@[specialize]
def
List.findSomeM?
{m : Type u → Type v}
[inst : Monad m]
{α : Type w}
{β : Type u}
(f : α → m (Option β))
:
Equations
- List.findSomeM? f [] = pure none
- List.findSomeM? f (a :: as) = do let a ← f a match a with | some b => pure (some b) | none => List.findSomeM? f as
@[inline]
def
List.forIn
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(as : List α)
(init : β)
(f : α → β → m (ForInStep β))
:
m β
Equations
- List.forIn as init f = (fun loop => loop as init) (List.forIn.loop f)
@[specialize]
def
List.forIn.loop
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(f : α → β → m (ForInStep β))
:
List α → β → m β
Equations
- List.forIn.loop f [] x = pure x
- List.forIn.loop f (a :: as) x = do let a ← f a x match a with | ForInStep.done b => pure b | ForInStep.yield b => List.forIn.loop f as b
@[simp]
theorem
List.forIn_cons
{m : Type u_1 → Type u_2}
{α : Type u_3}
{β : Type u_1}
[inst : Monad m]
(f : α → β → m (ForInStep β))
(a : α)
(as : List α)
(b : β)
:
forIn (a :: as) b f = do
let x ← f a b
match x with
| ForInStep.done b => pure b
| ForInStep.yield b => forIn as b f
@[simp]
theorem
List.forM_nil
{m : Type u_1 → Type u_2}
{α : Type u_3}
[inst : Monad m]
(f : α → m PUnit)
:
forM [] f = pure PUnit.unit