File: .lake/packages/lean4/src/lean/Init/Data/List/Control.lean

full_name: List.mapM.loop
code: /--
Applies the monadic action `f` on every element in the list, left-to-right, and returns the list of
results.

See `List.forM` for the variant that discards the results.
See `List.mapA` for the variant that works with `Applicative`.
-/
@[inline]
def mapM {m : Type u → Type v} [Monad m] {α : Type w} {β : Type u} (f : α → m β) (as : List α) : m (List β) 
goal: List α → List β → m (List β)

full_name: List.mapM
code: /--
Applies the monadic action `f` on every element in the list, left-to-right, and returns the list of
results.

See `List.forM` for the variant that discards the results.
See `List.mapA` for the variant that works with `Applicative`.
-/
@[inline]
def mapM {m : Type u → Type v} [Monad m] {α : Type w} {β : Type u} (f : α → m β) (as : List α) : m (List β) 
goal: m (List β)

full_name: List.mapA
code: /--
Applies the applicative action `f` on every element in the list, left-to-right, and returns the list of
results.

NB: If `m` is also a `Monad`, then using `mapM` can be more efficient.

See `List.forA` for the variant that discards the results.
See `List.mapM` for the variant that works with `Monad`.

**Warning**: this function is not tail-recursive, meaning that it may fail with a stack overflow on long lists.
-/
@[specialize]
def mapA {m : Type u → Type v} [Applicative m] {α : Type w} {β : Type u} (f : α → m β) : List α → m (List β)
  
goal: List α → m (List β)

full_name: List.forM
code: /--
Applies the monadic action `f` on every element in the list, left-to-right.

See `List.mapM` for the variant that collects results.
See `List.forA` for the variant that works with `Applicative`.
-/
@[specialize]
protected def forM {m : Type u → Type v} [Monad m] {α : Type w} (as : List α) (f : α → m PUnit) : m PUnit 
goal: m PUnit

full_name: List.forA
code: /--
Applies the applicative action `f` on every element in the list, left-to-right.

NB: If `m` is also a `Monad`, then using `forM` can be more efficient.

See `List.mapA` for the variant that collects results.
See `List.forM` for the variant that works with `Monad`.
-/
@[specialize]
def forA {m : Type u → Type v} [Applicative m] {α : Type w} (as : List α) (f : α → m PUnit) : m PUnit 
goal: m PUnit

full_name: List.filterAuxM
code: @[specialize]
def filterAuxM {m : Type → Type v} [Monad m] {α : Type} (f : α → m Bool) : List α → List α → m (List α)
  
goal: List α → List α → m (List α)

full_name: List.filterM
code: /--
Applies the monadic predicate `p` on every element in the list, left-to-right, and returns those
elements `x` for which `p x` returns `true`.
-/
@[inline]
def filterM {m : Type → Type v} [Monad m] {α : Type} (p : α → m Bool) (as : List α) : m (List α) 
goal: m (List α)

full_name: List.filterRevM
code: /--
Applies the monadic predicate `p` on every element in the list, right-to-left, and returns those
elements `x` for which `p x` returns `true`.
-/
@[inline]
def filterRevM {m : Type → Type v} [Monad m] {α : Type} (p : α → m Bool) (as : List α) : m (List α) 
goal: m (List α)

full_name: List.filterMapM.loop
code: /--
Applies the monadic function `f` on every element `x` in the list, left-to-right, and returns those
results `y` for which `f x` returns `some y`.
-/
@[inline]
def filterMapM {m : Type u → Type v} [Monad m] {α β : Type u} (f : α → m (Option β)) (as : List α) : m (List β) 
goal: List α → List β → m (List β)

full_name: List.filterMapM
code: /--
Applies the monadic function `f` on every element `x` in the list, left-to-right, and returns those
results `y` for which `f x` returns `some y`.
-/
@[inline]
def filterMapM {m : Type u → Type v} [Monad m] {α β : Type u} (f : α → m (Option β)) (as : List α) : m (List β) 
goal: m (List β)

full_name: List.foldlM
code: /--
Folds a monadic function over a list from left to right:
```
foldlM f x₀ [a, b, c] = do
  let x₁ ← f x₀ a
  let x₂ ← f x₁ b
  let x₃ ← f x₂ c
  pure x₃
```
-/
@[specialize]
protected def foldlM {m : Type u → Type v} [Monad m] {s : Type u} {α : Type w} : (f : s → α → m s) → (init : s) → List α → m s
  
goal: List α → m s

full_name: List.foldlM_nil
code: @[simp] theorem foldlM_nil [Monad m] (f : β → α → m β) (b) : [].foldlM f b = pure b 
goal: List.foldlM f b List.nil = pure b

full_name: List.foldlM_cons
code: @[simp] theorem foldlM_cons [Monad m] (f : β → α → m β) (b) (a) (l : List α) :
    (a :: l).foldlM f b = f b a >>= l.foldlM f 
goal: List.foldlM f b (a :: l) = do
  let init ← f b a
  List.foldlM f init l

full_name: List.foldrM
code: /--
Folds a monadic function over a list from right to left:
```
foldrM f x₀ [a, b, c] = do
  let x₁ ← f c x₀
  let x₂ ← f b x₁
  let x₃ ← f a x₂
  pure x₃
```
-/
@[inline]
def foldrM {m : Type u → Type v} [Monad m] {s : Type u} {α : Type w} (f : α → s → m s) (init : s) (l : List α) : m s 
goal: m s

full_name: List.foldrM_nil
code: @[simp] theorem foldrM_nil [Monad m] (f : α → β → m β) (b) : [].foldrM f b = pure b 
goal: List.foldrM f b List.nil = pure b

full_name: List.firstM
code: /--
Maps `f` over the list and collects the results with `<|>`.
```
firstM f [a, b, c] = f a <|> f b <|> f c <|> failure
```
-/
@[specialize]
def firstM {m : Type u → Type v} [Alternative m] {α : Type w} {β : Type u} (f : α → m β) : List α → m β
  
goal: List α → m β

full_name: List.anyM
code: @[specialize]
def anyM {m : Type → Type u} [Monad m] {α : Type v} (f : α → m Bool) : List α → m Bool
  
goal: List α → m Bool

full_name: List.allM
code: @[specialize]
def allM {m : Type → Type u} [Monad m] {α : Type v} (f : α → m Bool) : List α → m Bool
  
goal: List α → m Bool

full_name: List.findM?
code: @[specialize]
def findM? {m : Type → Type u} [Monad m] {α : Type} (p : α → m Bool) : List α → m (Option α)
  
goal: List α → m (Option α)

full_name: List.findSomeM?
code: @[specialize]
def findSomeM? {m : Type u → Type v} [Monad m] {α : Type w} {β : Type u} (f : α → m (Option β)) : List α → m (Option β)
  
goal: List α → m (Option β)

full_name: List.forIn
code: @[inline] protected def forIn {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : List α) (init : β) (f : α → β → m (ForInStep β)) : m β 
goal: m β

full_name: List.forIn.loop
code: @[inline] protected def forIn {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : List α) (init : β) (f : α → β → m (ForInStep β)) : m β 
goal: List α → β → m β

full_name: List.«instForIn_.lake»
code: instance : ForIn m (List α) α 
goal: ForIn m (List α) α

full_name: List.forIn_nil
code: @[simp] theorem forIn_nil [Monad m] (f : α → β → m (ForInStep β)) (b : β) : forIn [] b f = pure b 
goal: forIn List.nil b f = pure b

full_name: List.forIn_cons
code: @[simp] theorem forIn_cons [Monad m] (f : α → β → m (ForInStep β)) (a : α) (as : List α) (b : β)
    : forIn (a::as) b f = f a b >>= fun | ForInStep.done b => pure b | ForInStep.yield b => forIn as b f 
goal: 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

full_name: List.forIn'
code: @[inline] protected def forIn' {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : List α) (init : β) (f : (a : α) → a ∈ as → β → m (ForInStep β)) : m β 
goal: m β

full_name: List.forIn'.loop
code: @[inline] protected def forIn' {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : List α) (init : β) (f : (a : α) → a ∈ as → β → m (ForInStep β)) : m β 
goal: (Exists fun bs => bs ++ as' = as) → m β

full_name: List.«instForIn'InferInstanceMembership_.lake»
code: instance : ForIn' m (List α) α inferInstance 
goal: ForIn' m (List α) α inferInstance

full_name: List.forIn'_eq_forIn
code: @[simp] theorem forIn'_eq_forIn {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : List α) (init : β) (f : α → β → m (ForInStep β)) : forIn' as init (fun a _ b => f a b) = forIn as init f 
goal: (forIn' as init fun a x b => f a b) = forIn as init f

full_name: List.«instForM_.lake»
code: instance : ForM m (List α) α 
goal: ForM m (List α) α

full_name: List.forM_nil
code: @[simp] theorem forM_nil  [Monad m] (f : α → m PUnit) : forM [] f = pure ⟨⟩ 
goal: forM List.nil f = pure PUnit.unit

full_name: List.forM_cons
code: @[simp] theorem forM_cons [Monad m] (f : α → m PUnit) (a : α) (as : List α) : forM (a::as) f = f a >>= fun _ => forM as f 
goal: forM (a :: as) f = do
  f a
  forM as f

full_name: List.«instFunctor_.lake»
code: instance : Functor List 
goal: Functor List