Created
September 22, 2017 07:06
-
-
Save christiearcus/153a5d48ce76775df3e3e3255d9cc0fa to your computer and use it in GitHub Desktop.
Scala - Session 1
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
// Base types | |
val a: Int = 10 | |
// Functions | |
// first class citizens - can be passed as values. | |
def add(a: Int, b:Int): Int = { | |
a + b | |
} | |
// last line returns automatically. | |
// block scoped. | |
def addCurried(a: Int)(b: Int): Int = { | |
a + b | |
} | |
def add7(a: Int): Int = { | |
val x: Int => Int = addCurried(7) | |
val y = x(a) | |
y | |
} | |
add7(10) | |
add7(10) | |
add7(10) | |
add7(10) | |
// Referencial transparency | |
// You could replace the function | |
// with the result of the function anywhere | |
// and it would work | |
val stringBuilder = new StringBuilder("hello") | |
val meow = stringBuilder.append("world") | |
val cat = stringBuilder.append("world") | |
// Classes | |
class firstClass(a: Int = 10, b: String = "meowmeow") { | |
// define getters and setters to get anything | |
} | |
val christie = new firstClass() | |
// Trait | |
// Abstract (implementing in interface in Java) | |
// Case Classes mean you don't need to call the new keyword | |
// and you have a getter by default. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment