w1 scala courses
Improvments
Rendering utility function private by nesting them inside the main function.
We can make all those functions as closure since the x is visible
throughout the all block.
Renaming into w1
gcd
factorial
@tailrec on gcd
tail recursive factorial
sumInts + sumCubes + sumFactorials
Using higher-order function, factoring out common patterns
Map of functions to apply
Using anonymous function to declare the cube function
we can let the compiler infer the type
tail recursive version of the sum function
Reversing parameters, first the function, then the bounds
Redefining the sum function to return a function that takes the 2 bounds
parameters (currying)
Thus we can drop the redundants arguments (here the bounds)
We can remove the `middlemen` functions altogether
Special syntax to declare function that returns function in scala