Skip to content

Instantly share code, notes, and snippets.

@tlockney
Created September 14, 2016 17:21
Show Gist options
  • Save tlockney/1f6201ef894fa438407d19f9b997e990 to your computer and use it in GitHub Desktop.
Save tlockney/1f6201ef894fa438407d19f9b997e990 to your computer and use it in GitHub Desktop.
Simple example of right-biased Either
[info] Loading global plugins from /Users/tlockn/.sbt/0.13/plugins
[info] Set current project to eitherdemo (in build file:/Users/tlockn/tmp/eitherDemo/)
SBT  eitherdemo  set scalaVersion := "2.11.7"
[info] Defining *:scalaVersion
[info] The new value will be used by *:allDependencies, *:crossScalaVersions and 12 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to eitherdemo (in build file:/Users/tlockn/tmp/eitherDemo/)
SBT  eitherdemo  console
[info] Updating {file:/Users/tlockn/tmp/eitherDemo/}eitherdemo...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] 'compiler-interface' not yet compiled for Scala 2.11.7. Compiling...
[info] Compilation completed in 16.756 s
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_66).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val e: Either[String,String] = Right("foo")
e: Either[String,String] = Right(foo)
scala> e.map(println)
<console>:12: error: value map is not a member of Either[String,String]
e.map(println)
^
scala> e.right.map(println)
foo
res1: Product with Serializable with scala.util.Either[String,Unit] = Right(())
scala> :q
[success] Total time: 48 s, completed Sep 14, 2016 10:17:55 AM
SBT  eitherdemo  set scalaVersion := "2.12.0-RC1"
[info] Defining *:scalaVersion
[info] The new value will be used by *:allDependencies, *:crossScalaVersions and 12 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to eitherdemo (in build file:/Users/tlockn/tmp/eitherDemo/)
SBT  eitherdemo  console
[info] Updating {file:/Users/tlockn/tmp/eitherDemo/}eitherdemo...
[info] Resolving jline#jline;2.14.1 ...
[info] Done updating.
[info] Starting scala interpreter...
[info]
Welcome to Scala 2.12.0-RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_66).
Type in expressions for evaluation. Or try :help.
scala> val e: Either[String,String] = Right("foo")
e: Either[String,String] = Right(foo)
scala> e.map(println)
foo
res0: scala.util.Either[String,Unit] = Right(())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment