From 21db2e5e4f203f82bdb306eedf02283edd50237a Mon Sep 17 00:00:00 2001 From: Michael Bull Date: Tue, 18 Sep 2018 20:16:17 +0100 Subject: [PATCH] Mark new mapping functions as inline --- .../com/github/michaelbull/result/Iterable.kt | 16 ++++++++-------- .../kotlin/com/github/michaelbull/result/Map.kt | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/com/github/michaelbull/result/Iterable.kt b/src/main/kotlin/com/github/michaelbull/result/Iterable.kt index 83795fb..2b7a149 100644 --- a/src/main/kotlin/com/github/michaelbull/result/Iterable.kt +++ b/src/main/kotlin/com/github/michaelbull/result/Iterable.kt @@ -143,7 +143,7 @@ fun Iterable>.partition(): Pair, List> { * function to each element in the original collection, returning early with the first [Err] if a * transformation fails. */ -fun Iterable.mapResult(transform: (V) -> Result): Result, E> { +inline fun Iterable.mapResult(transform: (V) -> Result): Result, E> { return Ok(map { element -> val transformed = transform(element) @@ -159,7 +159,7 @@ fun Iterable.mapResult(transform: (V) -> Result): Result> Iterable.mapResultTo(destination: C, transform: (V) -> Result): Result { +inline fun > Iterable.mapResultTo(destination: C, transform: (V) -> Result): Result { return Ok(mapTo(destination) { element -> val transformed = transform(element) @@ -175,7 +175,7 @@ fun > Iterable.mapResultTo(destination: * given [transform] function to each element in the original collection, returning early with the * first [Err] if a transformation fails. */ -fun Iterable.mapResultNotNull(transform: (V) -> Result?): Result, E> { +inline fun Iterable.mapResultNotNull(transform: (V) -> Result?): Result, E> { return Ok(mapNotNull { element -> val transformed = transform(element) @@ -192,7 +192,7 @@ fun Iterable.mapResultNotNull(transform: (V) -> Result? * only the non-null results to the given [destination], returning early with the first [Err] if a * transformation fails. */ -fun > Iterable.mapResultNotNullTo(destination: C, transform: (V) -> Result?): Result { +inline fun > Iterable.mapResultNotNullTo(destination: C, transform: (V) -> Result?): Result { return Ok(mapNotNullTo(destination) { element -> val transformed = transform(element) @@ -209,7 +209,7 @@ fun > Iterable.mapResultNotNullTo( * function to each element and its index in the original collection, returning early with the * first [Err] if a transformation fails. */ -fun Iterable.mapResultIndexed(transform: (index: Int, V) -> Result): Result, E> { +inline fun Iterable.mapResultIndexed(transform: (index: Int, V) -> Result): Result, E> { return Ok(mapIndexed { index, element -> val transformed = transform(index, element) @@ -225,7 +225,7 @@ fun Iterable.mapResultIndexed(transform: (index: Int, V) -> Result< * and appends the results to the given [destination], returning early with the first [Err] if a * transformation fails. */ -fun > Iterable.mapResultIndexedTo(destination: C, transform: (index: Int, V) -> Result): Result { +inline fun > Iterable.mapResultIndexedTo(destination: C, transform: (index: Int, V) -> Result): Result { return Ok(mapIndexedTo(destination) { index, element -> val transformed = transform(index, element) @@ -241,7 +241,7 @@ fun > Iterable.mapResultIndexedTo(destin * given [transform] function to each element and its index in the original collection, returning * early with the first [Err] if a transformation fails. */ -fun Iterable.mapResultIndexedNotNull(transform: (index: Int, V) -> Result?): Result, E> { +inline fun Iterable.mapResultIndexedNotNull(transform: (index: Int, V) -> Result?): Result, E> { return Ok(mapIndexedNotNull { index, element -> val transformed = transform(index, element) @@ -258,7 +258,7 @@ fun Iterable.mapResultIndexedNotNull(transform: (index: Int, * and appends only the non-null results to the given [destination], returning early with the first * [Err] if a transformation fails. */ -fun > Iterable.mapResultIndexedNotNullTo(destination: C, transform: (index: Int, V) -> Result?): Result { +inline fun > Iterable.mapResultIndexedNotNullTo(destination: C, transform: (index: Int, V) -> Result?): Result { return Ok(mapIndexedNotNullTo(destination) { index, element -> val transformed = transform(index, element) diff --git a/src/main/kotlin/com/github/michaelbull/result/Map.kt b/src/main/kotlin/com/github/michaelbull/result/Map.kt index 60ada99..b03d9a2 100644 --- a/src/main/kotlin/com/github/michaelbull/result/Map.kt +++ b/src/main/kotlin/com/github/michaelbull/result/Map.kt @@ -35,7 +35,7 @@ inline infix fun Result.mapError(transform: (E) -> F): Result Result, E>.mapAll(transform: (V) -> Result): Result, E> { +inline infix fun Result, E>.mapAll(transform: (V) -> Result): Result, E> { return map { iterable -> iterable.map { element -> val transformed = transform(element)