Skip to content

Instantly share code, notes, and snippets.

@yoshiyoshifujii
Last active March 10, 2017 06:36
Show Gist options
  • Save yoshiyoshifujii/06341a920dd4a793f702cd7d50ac3b01 to your computer and use it in GitHub Desktop.
Save yoshiyoshifujii/06341a920dd4a793f702cd7d50ac3b01 to your computer and use it in GitHub Desktop.
def swap[L, R](a: Option[Either[L, R]]): Either[L, Option[R]] =
(for {
b <- a
} yield for {
c <- b.right
} yield Option(c)).getOrElse(Right(None))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment