Skip to content

Instantly share code, notes, and snippets.

@frgomes
Last active November 18, 2020 17:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frgomes/bf410885a719fb9f5d04a5c54c1fc18d to your computer and use it in GitHub Desktop.
Save frgomes/bf410885a719fb9f5d04a5c54c1fc18d to your computer and use it in GitHub Desktop.
Scala - Chaining Try/Success/Failure, return first successful
def a: Try[String] = Failure(new RuntimeException)
def b: Try[String] = Failure(new RuntimeException)
def c: Try[String] = Success("C")
def d: Try[String] = Failure(new RuntimeException)
def e: Try[String] = Success("E")
def f: Try[String] = Failure(new RuntimeException)
val result = a orElse b orElse c orElse d orElse e orElse f
// result is Success("C")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment