map -package:containers -package:conduit -package:imports -package:monoidal-containers -package:basement -package:invertible package:foldl -is:exact
Converts an effectful function to a fold. Specialized version of
sink.
Given a
Fold, produces a
HashMap which applies that fold
to each
a separated by key
k.
>>> List.sort (HashMap.toList (fold (foldByKeyHashMap Control.Foldl.sum) [("a",1), ("b",2), ("b",20), ("a",10)]))
[("a",11),("b",22)]
Given a
Fold, produces a
Map which applies that fold to
each
a separated by key
k.
>>> fold (foldByKeyMap Control.Foldl.sum) [("a",1), ("b",2), ("b",20), ("a",10)]
fromList [("a",11),("b",22)]
Convert a "
foldMap" to a
Fold
Fold pairs into a hash-map.
(postmapM f folder) returns a new
FoldM where f is
applied to the final value.
postmapM return = id
postmapM (f >=> g) = postmapM g . postmapM f
postmapM k (pure r) = k r
(premap f folder) returns a new
Fold where f is
applied at each step
fold (premap f folder) list = fold folder (List.map f list)
>>> fold (premap Sum Foldl.mconcat) [1..10]
Sum {getSum = 55}
>>> fold Foldl.mconcat (List.map Sum [1..10])
Sum {getSum = 55}
premap id = id
premap (f . g) = premap g . premap f
premap k (pure r) = pure r
premap k (f <*> x) = premap k f <*> premap k x
(premapM f folder) returns a new
FoldM where f is
applied to each input element
premapM return = id
premapM (f <=< g) = premap g . premap f
premapM k (pure r) = pure r
premapM k (f <*> x) = premapM k f <*> premapM k x
(premap f scaner) returns a new
Scan where f is
applied at each step
scan (premap f scaner) list = scan scaner (map f list)
premap id = id
premap (f . g) = premap g . premap f
premap k (pure r) = pure r
premap k (f <*> x) = premap k f <*> premap k x
(premapM f scaner) returns a new
ScanM where f is
applied to each input element
premapM return = id
premapM (f <=< g) = premap g . premap f
premapM k (pure r) = pure r
premapM k (f <*> x) = premapM k f <*> premapM k x