chore: upstream SMap.foldM (#4690)

This commit is contained in:
Kim Morrison 2024-07-09 03:11:58 +10:00 committed by GitHub
parent 3b3901b824
commit aecebaab74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -87,6 +87,11 @@ def switch (m : SMap α β) : SMap α β :=
@[inline] def foldStage2 {σ : Type w} (f : σα → β → σ) (s : σ) (m : SMap α β) : σ :=
m.map₂.foldl f s
/-- Monadic fold over a staged map. -/
def foldM {m : Type w → Type w} [Monad m]
(f : σα → β → m σ) (init : σ) (map : SMap α β) : m σ := do
map.map₂.foldlM f (← map.map₁.foldM f init)
def fold {σ : Type w} (f : σα → β → σ) (init : σ) (m : SMap α β) : σ :=
m.map₂.foldl f $ m.map₁.fold f init