Skip to content

Commit

Permalink
docs(Either): describe the all method
Browse files Browse the repository at this point in the history
this adds documentation to the `all` method, and
moves it closer to the very similar, but subtly
different `exists` function.

Fixes N/A
  • Loading branch information
Cody Mikol committed Oct 5, 2021
1 parent 805ea0d commit 13dc214
Showing 1 changed file with 16 additions and 3 deletions.
Expand Up @@ -881,6 +881,22 @@ public sealed class Either<out A, out B> {
public inline fun exists(predicate: (B) -> Boolean): Boolean =
fold({ false }, predicate)

/**
* Returns `true` if [Left] or returns the result of the application of
* the given predicate to the [Right] value.
*
* Example:
* ```
* Right(12).all { it > 10 } // Result: true
* Right(7).all { it > 10 } // Result: false
*
* val left: Either<Int, Int> = Left(12)
* left.all { it > 10 } // Result: false
* ```
*/
public inline fun all(predicate: (B) -> Boolean): Boolean =
fold({ true }, predicate)

/**
* Returns the right value if it exists, otherwise null
*
Expand Down Expand Up @@ -946,9 +962,6 @@ public sealed class Either<out A, out B> {
is Left -> null
}

public inline fun all(predicate: (B) -> Boolean): Boolean =
fold({ true }, predicate)

public fun isEmpty(): Boolean = isLeft

public fun isNotEmpty(): Boolean = isRight
Expand Down

0 comments on commit 13dc214

Please sign in to comment.