scala-collection-contrib icon indicating copy to clipboard operation
scala-collection-contrib copied to clipboard

add non-empty collection variants

Open scarf005 opened this issue 9 months ago • 1 comments
trafficstars

motivation:

it'd be nice to centralize nonempty collections into de-facto stdlib.

  • https://typelevel.org/cats/datatypes/nel.html
  • https://zio.dev/zio-prelude/functional-data-types/nonemptylist/
  • https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/

example usage:

scala> List().head
java.util.NoSuchElementException: head of empty list
  at scala.collection.immutable.Nil$.head(List.scala:663)
  at scala.collection.immutable.Nil$.head(List.scala:662)
  ... 30 elided
                                                                                                                                                                                                                                        scala> List().headOption
val res1: Option[Nothing] = None

scala> NonEmptyList(1).head
1

scarf005 avatar Feb 21 '25 04:02 scarf005