Last active
November 28, 2020 13:46
-
-
Save vladbatushkov/13dc3f69e438b8909a0c7a1cc2f44e7e to your computer and use it in GitHub Desktop.
reduce lite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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