equal
deleted
inserted
replaced
178 |
178 |
179 |
179 |
180 |
180 |
181 |
181 |
182 |
182 |
183 |
|
184 |
|
185 |
|
186 def my_flatten(lst: List[Option[Int]]): List[Int] = lst match { |
183 def my_flatten(lst: List[Option[Int]]): List[Int] = lst match { |
187 case Nil => Nil |
184 case Nil => Nil |
188 case None::xs => my_flatten(xs) |
185 case None::xs => my_flatten(xs) |
189 case Some(n)::xs => n::my_flatten(xs) |
186 case Some(n)::xs => n::my_flatten(xs) |
190 } |
187 } |
197 case 2 => "two" |
194 case 2 => "two" |
198 case _ => "many" |
195 case _ => "many" |
199 } |
196 } |
200 |
197 |
201 get_me_a_string(0) |
198 get_me_a_string(0) |
|
199 |
|
200 // you can also have cases combined |
|
201 def season(month: String) = month match { |
|
202 case "March" | "April" | "May" => "It's spring" |
|
203 case "June" | "July" | "August" => "It's summer" |
|
204 case "September" | "October" | "November" => "It's autumn" |
|
205 case "December" | "January" | "February" => "It's winter" |
|
206 } |
|
207 |
|
208 println(season("November")) |
202 |
209 |
203 // User-defined Datatypes |
210 // User-defined Datatypes |
204 //======================== |
211 //======================== |
205 |
212 |
206 abstract class Tree |
213 abstract class Tree |