Created
May 29, 2020 12:24
-
-
Save RyanSusana/a111845b18195f7d366afa661467468c to your computer and use it in GitHub Desktop.
This file contains 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
//Wraps all operands with a high-order function (the f parameter) | |
def sum(f: Int => Int, a: Int, b: Int): Int = | |
if (a > b) 0 else f(a) + sum(f, a + 1, b) | |
// Create a cubical sum of all ints from a to b | |
def sumCube(a: Int, b: Int) = sum(cube, a, b) | |
// Same for factorial | |
def sumFactorial(a: Int, b: Int) = sum(factorial, a, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment