From the package documentation of List
:
foldl : (a -> b -> b) -> b -> List a -> b
Reduce a list from the left.
foldl (+) 0 [1,2,3] == 6
foldl (::) [] [1,2,3] == [3,2,1]
So foldl step state [1,2,3]
is like saying:
state
|> step 1
|> step 2
|> step 3
foldr : (a -> b -> b) -> b -> List a -> b
Reduce a list from the right.
foldr (+) 0 [1,2,3] == 6
foldr (::) [] [1,2,3] == [1,2,3]
So foldr step state [1,2,3]
is like saying:
state
|> step 3
|> step 2
|> step 1
So I was wondering, from a design perspective, when is it better to have the user of an API plug a list into some wrapper for foldl
, and when is it better to have them use a pipeline like json-decode-pipeline
?
Thanks