Skip to content

Commit

Permalink
Deprecate getAll/getAllErrors in favour of valuesOf/errorsOf
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbull committed Mar 16, 2024
1 parent 7ce7c16 commit 522c821
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
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> {
return results.asIterable().filterValues()
}


/**
* Extracts from an [Iterable] of [Results][Result] all the [Ok] elements. All the [Ok] elements
* are extracted in order.
Expand All @@ -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)
*/
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> {
return results.asIterable().filterErrors()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 522c821

Please sign in to comment.