@[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 [] _fun_discr = pure _fun_discr
- List.filterAuxM f (h :: t) _fun_discr = do let b ← f h List.filterAuxM f t (bif b then h :: _fun_discr else _fun_discr)
@[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 = List.filterMapM.loop f (List.reverse as) []
@[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 [] _fun_discr = pure _fun_discr
- List.filterMapM.loop f (a :: as) _fun_discr = do let a ← f a match a with | none => List.filterMapM.loop f as _fun_discr | some b => List.filterMapM.loop f as (b :: _fun_discr)
@[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 _fun_discr _fun_discr [] = pure _fun_discr
- List.foldlM _fun_discr _fun_discr (a :: as) = do let s' ← _fun_discr _fun_discr a List.foldlM _fun_discr 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 _fun_discr _fun_discr [] = pure _fun_discr
- List.foldrM _fun_discr _fun_discr (a :: as) = do let s' ← List.foldrM _fun_discr _fun_discr as _fun_discr 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 = List.forIn.loop f as init
@[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 [] _fun_discr = pure _fun_discr
- List.forIn.loop f (a :: as) _fun_discr = do let a ← f a _fun_discr 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
@[inline]
def
List.forIn'
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(as : List α)
(init : β)
(f : (a : α) → a ∈ as → β → m (ForInStep β))
:
m β
Equations
- List.forIn' as init f = List.forIn'.loop as f as init (_ : ∃ bs, bs ++ as = as)
@[specialize]
def
List.forIn'.loop
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(as : List α)
(f : (a : α) → a ∈ as → β → m (ForInStep β))
:
Equations
- One or more equations did not get rendered due to their size.
- List.forIn'.loop as f [] _fun_discr x = pure _fun_discr
@[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