Created
June 28, 2013 15:48
-
-
Save saml/5885695 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
| def findFirstSuccess[A, B](f: A => B)(iter: Iterator[A]): Option[B] = { | |
| var result: Option[B] = None | |
| iter.find { a: A => | |
| Try { | |
| result = Option(f(a)) | |
| }.isSuccess | |
| } | |
| result | |
| } |
Author
yup thanks.
iter.map(x => Try(f(x))).collectFirst { case Success(y) => y }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def collectFirstSuccess[A,B](it: Iterator[A], f:A =>B) = it.map({i => Try(f(i))}).collectFirst({case Success(i) => i})