@[inline]
Combine all the values that can be represented by Fin n
with an initial value, starting at 0
and
nesting to the left.
Example:
Equations
- Fin.foldl n f init = Fin.foldl.loop✝ n f init 0
Instances For
@[inline]
Combine all the values that can be represented by Fin n
with an initial value, starting at n - 1
and nesting to the right.
Example:
Equations
- Fin.foldr n f init = Fin.foldr.loop✝ n f n ⋯ init
Instances For
@[inline]
def
Fin.foldlM
{m : Type u_1 → Type u_2}
{α : Type u_1}
[Monad m]
(n : Nat)
(f : α → Fin n → m α)
(init : α)
:
m α
Folds a monadic function over all the values in Fin n
from left to right, starting with 0
.
It is the sequence of steps:
Fin.foldlM n f x₀ = do
let x₁ ← f x₀ 0
let x₂ ← f x₁ 1
...
let xₙ ← f xₙ₋₁ (n-1)
pure xₙ
Equations
- Fin.foldlM n f init = Fin.foldlM.loop✝ n f init 0
Instances For
@[inline]
def
Fin.foldrM
{m : Type u_1 → Type u_2}
{α : Type u_1}
[Monad m]
(n : Nat)
(f : Fin n → α → m α)
(init : α)
:
m α
Folds a monadic function over Fin n
from right to left, starting with n-1
.
It is the sequence of steps:
Fin.foldrM n f xₙ = do
let xₙ₋₁ ← f (n-1) xₙ
let xₙ₋₂ ← f (n-2) xₙ₋₁
...
let x₀ ← f 0 x₁
pure x₀
Equations
- Fin.foldrM n f init = Fin.foldrM.loop✝ n f ⟨n, ⋯⟩ init
Instances For
foldlM #
theorem
Fin.foldlM_succ_last
{m : Type u_1 → Type u_2}
{α : Type u_1}
{n : Nat}
[Monad m]
[LawfulMonad m]
(f : α → Fin (n + 1) → m α)
:
Variant of foldlM_succ
that splits off Fin.last n
rather than 0
.