Here is a minimal function for a fold which operates the standard way.

fold : (b -> a -> b) -> b -> List a -> b
fold f =
    List.foldl (flip f)

Example use:

fold (++) "" ["a", "b", "c"]
-- result: (("" ++ "a") ++ "b") ++ "c"
--      == "" ++ "a" ++ "b" ++ "c"
--      == "abc"


Additionally, here is a minimal function for a right fold where the call 
visually matches how it works.

foldBack : (a -> b -> b) -> List a -> b -> b
foldBack f =
    flip (List.foldr f)

Example use:

foldBack (::) ["a", "b", "c"] []
-- result: "a" :: ("b" :: ("c" :: []))
--      == "a" :: "b" :: "c" :: []
--      == ["a", "b", "c"]

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to