@[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
Instances For
@[specialize #[]]
Inner loop for Fin.foldl
. Fin.foldl.loop n f x i = f (f (f x i) ...) (n-1)
Equations
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
Instances For
@[specialize #[]]
Inner loop for Fin.foldr
. Fin.foldr.loop n f i x = f 0 (f ... (f (i-1) x))
Equations
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
Instances For
@[specialize #[]]
def
Fin.foldlM.loop
{m : Type u_1 → Type u_2}
{α : Type u_1}
[Monad m]
(n : Nat)
(f : α → Fin n → m α)
(x : α)
(i : Nat)
:
m α
Inner loop for Fin.foldlM
.
Fin.foldlM.loop n f xᵢ i = do
let xᵢ₊₁ ← f xᵢ i
...
let xₙ ← f xₙ₋₁ (n-1)
pure xₙ
Equations
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
Instances For
@[specialize #[]]
def
Fin.foldrM.loop
{m : Type u_1 → Type u_2}
{α : Type u_1}
[Monad m]
(n : Nat)
(f : Fin n → α → m α)
:
Inner loop for Fin.foldrM
.
Fin.foldrM.loop n f i xᵢ = do
let xᵢ₋₁ ← f (i-1) xᵢ
...
let x₁ ← f 1 x₂
let x₀ ← f 0 x₁
pure x₀
Equations
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
.