Created
May 8, 2014 03:25
-
-
Save wmfairuz/0980f37f25e21e133982 to your computer and use it in GitHub Desktop.
scala-cheatsheet
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
| val a:Int = 0 // immutable | |
| var b:Int = 0 // mutable | |
| def foo(a: Int): Int = ??? // function definition | |
| // anonymous function. (x: Int) is parameter. x * x is body | |
| (x: Int) => x * x | |
| // above can be rewriten with (with a name f) | |
| def f(x:Int): Int = x * x | |
| // function that accept another function in argument | |
| def f(g: Int => Int, a: Int): Int = f(a) + a | |
| // function that returns another function | |
| def f(a: Int): Int => Int = { | |
| def g(b: Int): Int = { ??? } | |
| g | |
| } | |
| // above can be rewriten with... | |
| def f(a: Int)(b: Int): Int = { ??? } | |
| // Type of f ? | |
| def f(a: Int => Int)(b: Int, c: Int): Int = ... | |
| (Int => Int) => (Int, Int) => Int | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment