From 522c821fdf45363c0f3d60b29b37bb958af90839 Mon Sep 17 00:00:00 2001 From: Michael Bull Date: Sat, 16 Mar 2024 20:30:38 +0000 Subject: [PATCH] Deprecate getAll/getAllErrors in favour of valuesOf/errorsOf --- .../com/github/michaelbull/result/Iterable.kt | 17 +++++++++++++++++ .../github/michaelbull/result/IterableTest.kt | 8 ++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Iterable.kt b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Iterable.kt index 3ac2ba0..bd0b95b 100644 --- a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Iterable.kt +++ b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Iterable.kt @@ -166,10 +166,19 @@ public fun Iterable>.combine(): Result, E> { * * - Haskell: [Data.Either.lefts](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:lefts) */ +public fun > valuesOf(vararg results: R): List { + return results.asIterable().filterValues() +} + +@Deprecated( + message = "Use allValuesOf instead", + replaceWith = ReplaceWith("valuesOf(results)") +) public fun > getAll(vararg results: R): List { return results.asIterable().filterValues() } + /** * Extracts from an [Iterable] of [Results][Result] all the [Ok] elements. All the [Ok] elements * are extracted in order. @@ -191,6 +200,14 @@ public fun Iterable>.getAll(): List { * * - Haskell: [Data.Either.rights](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:rights) */ +public fun > errorsOf(vararg results: R): List { + return results.asIterable().filterErrors() +} + +@Deprecated( + message = "Use errorsOf instead", + replaceWith = ReplaceWith("errorsOf(results)") +) public fun > getAllErrors(vararg results: R): List { return results.asIterable().filterErrors() } diff --git a/kotlin-result/src/commonTest/kotlin/com/github/michaelbull/result/IterableTest.kt b/kotlin-result/src/commonTest/kotlin/com/github/michaelbull/result/IterableTest.kt index 1ffe99c..3442ee0 100644 --- a/kotlin-result/src/commonTest/kotlin/com/github/michaelbull/result/IterableTest.kt +++ b/kotlin-result/src/commonTest/kotlin/com/github/michaelbull/result/IterableTest.kt @@ -113,11 +113,11 @@ class IterableTest { } } - class GetAll { + class ValuesOf { @Test fun returnsAllValues() { - val result = getAll( + val result = valuesOf( Ok("hello"), Ok("big"), Err(IterableError.IterableError2), @@ -133,11 +133,11 @@ class IterableTest { } } - class GetAllErrors { + class ErrorsOf { @Test fun returnsAllErrors() { - val result = getAllErrors( + val result = errorsOf( Err(IterableError.IterableError2), Ok("haskell"), Err(IterableError.IterableError2),