@[specialize #[]]
Combine all the values that can be represented by Fin n with an initial value, starting at 0 and
nesting to the left.
Example:
Instances For
@[specialize #[]]
Inner loop for Fin.foldl. Fin.foldl.loop n f x i = f (f (f x i) ...) (n-1).
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:
Instances For
@[specialize #[]]
Inner loop for Fin.foldr. Fin.foldr.loop n f i x = f 0 (f ... (f (i-1) x))
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ₙ
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₀
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.