Skip to content

Instantly share code, notes, and snippets.

@deeperunderstanding
Created November 8, 2019 17:37
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/a75ba8756ea67d719308d30a1aa42c2d to your computer and use it in GitHub Desktop.
Save deeperunderstanding/a75ba8756ea67d719308d30a1aa42c2d to your computer and use it in GitHub Desktop.
object TrySequence {
operator fun <T> Try<T>.component1(): T = when (this) {
is Success -> this.value
is Failure -> throw this.error
}
}
fun <T> Try.Companion.sequential(func: TrySequence.() -> T): Try<T> {
return Try { func(TrySequence) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment