diff --git a/src/main/kotlin/com/mikebull94/result/Iterable.kt b/src/main/kotlin/com/mikebull94/result/Iterable.kt index e29b201..28b0399 100644 --- a/src/main/kotlin/com/mikebull94/result/Iterable.kt +++ b/src/main/kotlin/com/mikebull94/result/Iterable.kt @@ -20,7 +20,10 @@ inline fun Iterable.fold( return ok(accumulator) } -inline fun List.foldRight(initial: R, operation: (T, acc: R) -> Result): Result { +inline fun List.foldRight( + initial: R, + operation: (T, acc: R) -> Result +): Result { var accumulator = initial if (!isEmpty()) { diff --git a/src/main/kotlin/com/mikebull94/result/Map.kt b/src/main/kotlin/com/mikebull94/result/Map.kt index 8c9fcbb..b840c22 100644 --- a/src/main/kotlin/com/mikebull94/result/Map.kt +++ b/src/main/kotlin/com/mikebull94/result/Map.kt @@ -26,7 +26,10 @@ inline fun Result.mapError(transform: (E) -> U): Result { * - Elm: [Result.Extra.mapBoth](http://package.elm-lang.org/packages/circuithub/elm-result-extra/1.4.0/Result-Extra#mapBoth) * - Haskell: [Data.Either.either](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:either) */ -inline fun Result.mapBoth(success: (V) -> U, failure: (E) -> U): U { +inline fun Result.mapBoth( + success: (V) -> U, + failure: (E) -> U +): U { return when (this) { is Ok -> success(value) is Error -> failure(error) @@ -38,11 +41,11 @@ inline fun Result.mapBoth(success: (V) -> U, failure: (E) -> U): * - Haskell: [Data.Bifunctor.Bimap](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Bifunctor.html#v:bimap) */ inline fun Result.mapEither( - okTransform: (V1) -> V2, - errorTransform: (E1) -> E2 + success: (V1) -> V2, + failure: (E1) -> E2 ): Result { return when (this) { - is Ok -> ok(okTransform(value)) - is Error -> error(errorTransform(error)) + is Ok -> ok(success(value)) + is Error -> error(failure(error)) } } diff --git a/src/test/kotlin/com/mikebull94/result/MapTest.kt b/src/test/kotlin/com/mikebull94/result/MapTest.kt index 322c0fb..a667779 100644 --- a/src/test/kotlin/com/mikebull94/result/MapTest.kt +++ b/src/test/kotlin/com/mikebull94/result/MapTest.kt @@ -58,8 +58,8 @@ internal class MapTest { @Test internal fun `mapBoth should return the transformed result value if ok`() { val value = ok("there is").mapBoth( - { "$it a light" }, - { MapError.CustomError("$it that never") } + success = { "$it a light" }, + failure = { MapError.CustomError("$it that never") } ) as String assertThat(value, equalTo("there is a light")) @@ -68,8 +68,8 @@ internal class MapTest { @Test internal fun `mapBoth should return the transformed result error if not ok`() { val error = error(MapError.CustomError("this")).mapBoth( - { "$it charming" }, - { MapError.CustomError("${it.reason} man") } + success = { "$it charming" }, + failure = { MapError.CustomError("${it.reason} man") } ) as MapError.CustomError assertThat(error.reason, equalTo("this man")) @@ -78,8 +78,8 @@ internal class MapTest { @Test internal fun `mapEither should return the transformed result value if ok`() { val result = ok(500).mapEither( - { it + 500 }, - { MapError.CustomError(it) } + success = { it + 500 }, + failure = { MapError.CustomError(it) } ) result as Ok @@ -90,8 +90,8 @@ internal class MapTest { @Test internal fun `mapEither should return the transformed result error if not ok`() { val result = error("the reckless").mapEither( - { "the wild youth" }, - { MapError.CustomError("the truth") } + success = { "the wild youth" }, + failure = { MapError.CustomError("the truth") } ) result as Error