Skip to content

Instantly share code, notes, and snippets.

@deeperunderstanding
Last active November 22, 2019 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deeperunderstanding/919e024808b692a09ea54746e6f9c59c to your computer and use it in GitHub Desktop.
Save deeperunderstanding/919e024808b692a09ea54746e6f9c59c to your computer and use it in GitHub Desktop.
typealias ResultSet<T> = Pair<List<Success<T>>, List<Failure<T>>>
fun <T> List<Try<T>>.asResultSet(): ResultSet<T> = this.partition { it is Success } as ResultSet<T>
fun <T, R> ResultSet<T>.map(transform: (T) -> R): ResultSet<R> =
this.first.map { it.map(transform) }.asResultSet().let { result ->
Pair(result.first, this.second as List<Failure<R>> + result.second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment