Skip to content

Commit 9997f10

Browse files
authored
Merge pull request #5 from qoncept/dev
Change `map` as an extension of `Result`
2 parents 6d3f3a4 + 6188234 commit 9997f10

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/jp/co/qoncept/kotres/Result.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ sealed class Result<out T, out E: Exception> {
1111
class Failure<T, E: Exception>(override val exception: E): Result<T, E>() {
1212
override val value: T? = null
1313
}
14+
}
1415

15-
inline fun <R> map(transform: (T) -> R): Result<R, E> {
16-
return when (this) {
17-
is Success -> Success(transform(value))
18-
is Failure -> Failure(exception)
19-
}
16+
inline fun <T, R, E: Exception> Result<T, E>.map(transform: (T) -> R): Result<R, E> {
17+
return when (this) {
18+
is Result.Success -> Result.Success(transform(value))
19+
is Result.Failure -> Result.Failure(exception)
2020
}
2121
}
2222

0 commit comments

Comments
 (0)