History

Add foldlM

Needed for self hosting, and probably ought to be in the prelude by the usual rule of thumb

Edwin Brady committed 6 years ago

Commit 463f1b31 parent 1acbf1b1 file · +6 −0Browse files

Unified · Split

libs/prelude/Prelude.idr+6−0
@@ -580,6 +580,12 @@ interface Foldable (t : Type -> Type) where · 579 unmodified lines
580 foldl : (func : acc -> elem -> acc) -> (init : acc) -> (input : t elem) -> acc580 foldl : (func : acc -> elem -> acc) -> (init : acc) -> (input : t elem) -> acc
581 foldl f z t = foldr (flip (.) . flip f) id t z581 foldl f z t = foldr (flip (.) . flip f) id t z
582 582
583||| Similar to `foldl`, but uses a function wrapping its result in a `Monad`.
584||| Consequently, the final value is wrapped in the same `Monad`.
585public export
586foldlM : (Foldable t, Monad m) => (funcM: a -> b -> m a) -> (init: a) -> (input: t b) -> m a
587foldlM fm a0 = foldl (\ma,b => ma >>= flip fm b) (pure a0)
588
583||| Combine each element of a structure into a monoid.589||| Combine each element of a structure into a monoid.
584public export590public export
585concat : (Foldable t, Monoid a) => t a -> a591concat : (Foldable t, Monoid a) => t a -> a

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t