Skip to content

Commit 85312a8

Browse files
committed
intro zu options gestrichen bzw. gestrafft
1 parent d256c6e commit 85312a8

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// ====================================
2+
// Intro
3+
// ====================================
4+
val notebookMapOfElvis = Map(
5+
"Patricia" -> "Dell", "Rainer" -> "Dell",
6+
"Ingo" -> "Apple", "Rainer" -> "Dell")
7+
8+
// TODO -1- whats happend if the name not exists?
9+
def getNotebook(teamMember: String): String = {
10+
// TODO -2- can you return a null like in Java?
11+
notebookMapOfElvis.get(teamMember).getOrElse("n/a")
12+
}
13+
14+
// TODO -1- Implement the getNotebook method
15+
val ingosNotebook = getNotebook("Ingo")
16+
println(s"Ingo has a ${ingosNotebook}")
17+
assert(ingosNotebook == "Apple")
18+
19+
// TODO -2- Does the getNotebook method work for 'steffensNotebook'?
20+
val steffensNotebook = getNotebook("Steffen")
21+
println(s"Steffen has a ${steffensNotebook}")
22+
23+
24+
// Option is a ..
25+
// .. datatype to represent optional values
26+
// .. value that could be exists or not.
27+
// solve the NULL check hell in Java
28+
29+
// two implementations of abstract class 'Option'
30+
31+
// ====================================
32+
// Some
33+
// ====================================
34+
// 1 case class Some
35+
// represents existing values of type
36+
val some1 = Some(1234)
37+
38+
val some2 = Option.apply(2)
39+
40+
41+
// ====================================
42+
// None
43+
// ====================================
44+
45+
// 2 case object None
46+
// represents non-existent values
47+
val none1 = Option.empty
48+
49+
val none2 = None
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
val notebookMapOfElvis = Map("Patricia" -> "Dell",
2+
"Rainer" -> "Dell",
3+
"Ingo" -> "Apple",
4+
"Rainer" -> "Dell")
5+
6+
// TODO -1- whats happend if the name not exists?
7+
def getNotebook(teamMember: String): String = {
8+
// TODO -2- can you return a null like in Java?
9+
???
10+
}
11+
12+
// TODO -1- Implement the getNotebook method
13+
val ingosNotebook = getNotebook("Ingo")
14+
println(s"Ingo has a ${ingosNotebook}")
15+
assert(ingosNotebook == "Apple")
16+
17+
// TODO -2- Does the getNotebook method work for 'steffensNotebook'?
18+
val steffensNotebook = ???
19+
println(s"Steffen has a ${steffensNotebook}")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Option is a
2+
// ... datatype to represent optional values
3+
4+
5+
// 1 case class Some
6+
// represents existing values of type
7+
val some1 = ???
8+
9+
val some2 = ???
10+
11+
// TODO -me- go into the scala class
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Option is a ..
2+
// .. datatype to represent optional values
3+
4+
// 2 case object None
5+
// represents non-existent values
6+
val none1 = ???
7+
8+
val none2 = ???
9+
10+
// TODO -me- go into the scala class

0 commit comments

Comments
 (0)