alvinj / FunctionalProgrammingSimplified

Notes and projects for my book, “Functional Programming, Simplified"
18 stars 2 forks source link

page 163: side effect and return type is Unit #24

Open peteanning opened 5 years ago

peteanning commented 5 years ago
val evenOrOdd = i match {
    case 1 | 3 | 5 | 7 | 9 => println("odd")
    case 2 | 4 | 6 | 8 | 10 => println("even")
}

I think this should just be:

val evenOrOdd = i match {
    case 1 | 3 | 5 | 7 | 9 => "odd"
    case 2 | 4 | 6 | 8 | 10 => "even"
}

If not the type of val evenOrOdd is Unit