From 6d85179cfdb10a8e53e3bf395f06a2ccf2347e45 Mon Sep 17 00:00:00 2001 From: Lola Denney Date: Sat, 7 Mar 2026 22:09:32 -0500 Subject: [PATCH 1/2] added doctest for forall and exists --- core/src/main/scala/cats/data/NonEmptyList.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/src/main/scala/cats/data/NonEmptyList.scala b/core/src/main/scala/cats/data/NonEmptyList.scala index b898ae1af2..014fd99502 100644 --- a/core/src/main/scala/cats/data/NonEmptyList.scala +++ b/core/src/main/scala/cats/data/NonEmptyList.scala @@ -280,12 +280,28 @@ final case class NonEmptyList[+A](head: A, tail: List[A]) extends NonEmptyCollec /** * Check whether at least one element satisfies the predicate + * {{{ + * scala> import cats.data.NonEmptyList + * scala> val nel = NonEmptyList.of(1, 2, 3, 4, 5) + * scala> nel.exists(_ => false) + * res0: scala.Boolean = false + * scala> nel.exists(i => i > 2) + * res1: scala.Boolean = true + * }}} */ def exists(p: A => Boolean): Boolean = p(head) || tail.exists(p) /** * Check whether all elements satisfy the predicate + * {{{ + * scala> import cats.data.NonEmptyList + * scala> val nel = NonEmptyList.of(1, 2, 3, 4, 5) + * scala> nel.forall(_ > 0) + * res0: scala.Boolean = true + * scala> nel.forall(i => i > 2) + * res1: scala.Boolean = false + * }}} */ def forall(p: A => Boolean): Boolean = p(head) && tail.forall(p) From 0b7a2d5f13b7bdaf0a6f9f7b16d9b73a21389ac5 Mon Sep 17 00:00:00 2001 From: L Denney <156242030+loladenney@users.noreply.github.com> Date: Sun, 8 Mar 2026 13:58:13 -0400 Subject: [PATCH 2/2] Update core/src/main/scala/cats/data/NonEmptyList.scala Co-authored-by: Andrew Valencik --- core/src/main/scala/cats/data/NonEmptyList.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/scala/cats/data/NonEmptyList.scala b/core/src/main/scala/cats/data/NonEmptyList.scala index 014fd99502..0d8af3c113 100644 --- a/core/src/main/scala/cats/data/NonEmptyList.scala +++ b/core/src/main/scala/cats/data/NonEmptyList.scala @@ -283,7 +283,7 @@ final case class NonEmptyList[+A](head: A, tail: List[A]) extends NonEmptyCollec * {{{ * scala> import cats.data.NonEmptyList * scala> val nel = NonEmptyList.of(1, 2, 3, 4, 5) - * scala> nel.exists(_ => false) + * scala> nel.exists(i => i > 100) * res0: scala.Boolean = false * scala> nel.exists(i => i > 2) * res1: scala.Boolean = true