Created
November 8, 2019 12:16
-
-
Save deeperunderstanding/22af05f14a7a9e5611ee646d94b69697 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
fun <T, R> Try.Companion.traverse(list: List<T>, transform: (T) -> Try<R>): Try<List<R>> = Try { | |
val newList = mutableListOf<R>() | |
for (value in list) { | |
when(val result = transform(value)) { | |
is Success -> newList.add(result.value) | |
is Failure -> throw result.error | |
} | |
} | |
newList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment