Last active
January 19, 2018 18:10
-
-
Save gustavofranke/b6a1ce63f76dfef4aeac47880d1e0391 to your computer and use it in GitHub Desktop.
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: List[Int] = Nil | |
a: List[Int] = List() | |
scala> a map {x => x + 2 } | |
res0: List[Int] = List() | |
scala> val a = Nil | |
a: scala.collection.immutable.Nil.type = List() | |
scala> a map {x => x + 2 } | |
<console>:13: error: value + is not a member of Nothing | |
a map {x => x+2 } | |
^ | |
scala> val a: List[String] = Nil | |
a: List[String] = List() | |
scala> a map {x => x + "2" } | |
res2: List[String] = List() | |
scala> val a:Option[Int] = None | |
a: Option[Int] = None | |
scala> a.get | |
java.util.NoSuchElementException: None.get | |
at scala.None$.get(Option.scala:349) | |
at scala.None$.get(Option.scala:347) | |
... 29 elided | |
scala> a map {x => x + 2 } | |
res10: Option[Int] = None | |
scala> val a:Option[Int] = Some(5) | |
a: Option[Int] = Some(5) | |
scala> a map {x => x + 2 } | |
res11: Option[Int] = Some(7) | |
scala> import scala.util.Failure | |
import scala.util.Failure | |
scala> import scala.util.Success | |
import scala.util.Success | |
scala> val a: Try[Int] = Try(5/0) | |
a: scala.util.Try[Int] = Failure(java.lang.ArithmeticException: / by zero) | |
scala> a map {x => x+2 } | |
res0: scala.util.Try[Int] = Failure(java.lang.ArithmeticException: / by zero) | |
scala> a.foldRight(0)(_ + _) | |
res10: Int = 10 | |
scala> a.foldRight(1)(_ * _) | |
res11: Int = 24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment