From 13dc2141647efa0d9a4bca57c47acfc5bb6252d4 Mon Sep 17 00:00:00 2001 From: Cody Mikol Date: Mon, 4 Oct 2021 22:05:59 -0400 Subject: [PATCH] docs(Either): describe the `all` method this adds documentation to the `all` method, and moves it closer to the very similar, but subtly different `exists` function. Fixes N/A --- .../commonMain/kotlin/arrow/core/Either.kt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index 10520b7e59f..2856a833205 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -881,6 +881,22 @@ public sealed class Either { 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 = 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 * @@ -946,9 +962,6 @@ public sealed class Either { is Left -> null } - public inline fun all(predicate: (B) -> Boolean): Boolean = - fold({ true }, predicate) - public fun isEmpty(): Boolean = isLeft public fun isNotEmpty(): Boolean = isRight