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