Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(Either): describe the all method #2551

Merged
merged 2 commits into from Dec 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -954,6 +954,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: true
* ```
*/
public inline fun all(predicate: (B) -> Boolean): Boolean =
fold({ true }, predicate)

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

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

/**
* Returns `true` if [Left]
*
Expand Down