September 2018
Intermediate to advanced
398 pages
9h 43m
English
As its name implies, the cats.data.NonEmptyList type represents a List instance that has at least one element. In other words, it is a List instance that cannot be empty. The following are some examples of this usage that you can retype in a new Scala worksheet:
import cats.data.NonEmptyListNonEmptyList(1, List(2, 3))// res0: cats.data.NonEmptyList[Int] = NonEmptyList(1, 2, 3)NonEmptyList.fromList(List(1, 2, 3))// res3: Option[cats.data.NonEmptyList[Int]] = Some(NonEmptyList(1, 2, 3))NonEmptyList.fromList(List.empty[Int])// res4: Option[cats.data.NonEmptyList[Int]] = Noneval nel = NonEmptyList.of(1, 2, 3)// nel: cats.data.NonEmptyList[Int] = NonEmptyList(1, 2, 3)nel.head// res0: Int = 1nel.tail// res1: List[Int] = ...
Read now
Unlock full access