Deprecate getAll/getAllErrors in favour of valuesOf/errorsOf

This commit is contained in:
Michael Bull 2024-03-16 20:30:38 +00:00
parent 7ce7c16d7f
commit 522c821fdf
2 changed files with 21 additions and 4 deletions

View File

@ -166,10 +166,19 @@ public fun <V, E> Iterable<Result<V, E>>.combine(): Result<List<V>, E> {
* *
* - Haskell: [Data.Either.lefts](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:lefts) * - Haskell: [Data.Either.lefts](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:lefts)
*/ */
public fun <V, E, R : Result<V, E>> valuesOf(vararg results: R): List<V> {
return results.asIterable().filterValues()
}
@Deprecated(
message = "Use allValuesOf instead",
replaceWith = ReplaceWith("valuesOf(results)")
)
public fun <V, E, R : Result<V, E>> getAll(vararg results: R): List<V> { public fun <V, E, R : Result<V, E>> getAll(vararg results: R): List<V> {
return results.asIterable().filterValues() return results.asIterable().filterValues()
} }
/** /**
* Extracts from an [Iterable] of [Results][Result] all the [Ok] elements. All the [Ok] elements * Extracts from an [Iterable] of [Results][Result] all the [Ok] elements. All the [Ok] elements
* are extracted in order. * are extracted in order.
@ -191,6 +200,14 @@ public fun <V, E> Iterable<Result<V, E>>.getAll(): List<V> {
* *
* - Haskell: [Data.Either.rights](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:rights) * - Haskell: [Data.Either.rights](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:rights)
*/ */
public fun <V, E, R : Result<V, E>> errorsOf(vararg results: R): List<E> {
return results.asIterable().filterErrors()
}
@Deprecated(
message = "Use errorsOf instead",
replaceWith = ReplaceWith("errorsOf(results)")
)
public fun <V, E, R : Result<V, E>> getAllErrors(vararg results: R): List<E> { public fun <V, E, R : Result<V, E>> getAllErrors(vararg results: R): List<E> {
return results.asIterable().filterErrors() return results.asIterable().filterErrors()
} }

View File

@ -113,11 +113,11 @@ class IterableTest {
} }
} }
class GetAll { class ValuesOf {
@Test @Test
fun returnsAllValues() { fun returnsAllValues() {
val result = getAll( val result = valuesOf(
Ok("hello"), Ok("hello"),
Ok("big"), Ok("big"),
Err(IterableError.IterableError2), Err(IterableError.IterableError2),
@ -133,11 +133,11 @@ class IterableTest {
} }
} }
class GetAllErrors { class ErrorsOf {
@Test @Test
fun returnsAllErrors() { fun returnsAllErrors() {
val result = getAllErrors( val result = errorsOf(
Err(IterableError.IterableError2), Err(IterableError.IterableError2),
Ok("haskell"), Ok("haskell"),
Err(IterableError.IterableError2), Err(IterableError.IterableError2),