Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Last active November 28, 2020 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladbatushkov/13dc3f69e438b8909a0c7a1cc2f44e7e to your computer and use it in GitHub Desktop.
Save vladbatushkov/13dc3f69e438b8909a0c7a1cc2f44e7e to your computer and use it in GitHub Desktop.
reduce lite
add : Int -> Int -> Int
add a b =
a + b
dashify : String -> String -> String
dashify a b =
if a == "" then
b
else
a ++ "-" ++ b
reduce : (a -> a -> a) -> a -> Maybe (List a) -> a
reduce func acc list =
case list of
Nothing ->
acc
Just l ->
let
next =
List.head l
res =
case next of
Nothing ->
acc
Just n ->
func acc n
in
reduce func res <| List.tail l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment