Last active
November 18, 2020 17:45
-
-
Save frgomes/bf410885a719fb9f5d04a5c54c1fc18d to your computer and use it in GitHub Desktop.
Scala - Chaining Try/Success/Failure, return first successful
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
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