Skip to content

Commit

Permalink
Merge pull request #5 from qoncept/dev
Browse files Browse the repository at this point in the history
Change `map` as an extension of `Result`
  • Loading branch information
koher authored Jan 23, 2017
2 parents 6d3f3a4 + 6188234 commit 9997f10
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/jp/co/qoncept/kotres/Result.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ sealed class Result<out T, out E: Exception> {
class Failure<T, E: Exception>(override val exception: E): Result<T, E>() {
override val value: T? = null
}
}

inline fun <R> map(transform: (T) -> R): Result<R, E> {
return when (this) {
is Success -> Success(transform(value))
is Failure -> Failure(exception)
}
inline fun <T, R, E: Exception> Result<T, E>.map(transform: (T) -> R): Result<R, E> {
return when (this) {
is Result.Success -> Result.Success(transform(value))
is Result.Failure -> Result.Failure(exception)
}
}

Expand Down

0 comments on commit 9997f10

Please sign in to comment.