Packages

final case class NonEmptyList[+A](head: A, tail: List[A]) extends NonEmptyCollection[A, List, NonEmptyList] with Product with Serializable

A data type which represents a non empty list of A, with single element (head) and optional structure (tail).

Source
NonEmptyList.scala
Linear Supertypes
Serializable, Product, Equals, NonEmptyCollection[A, List, NonEmptyList], AnyRef, Any
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. NonEmptyList
  2. Serializable
  3. Product
  4. Equals
  5. NonEmptyCollection
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new NonEmptyList(head: A, tail: List[A])

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. def ++[AA >: A](l: List[AA]): NonEmptyList[AA]
  4. def ++:[AA >: A](other: List[AA]): NonEmptyList[AA]

    Alias for prependList

    Alias for prependList

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3)
    scala> val list = List(-1, 0)
    scala> list ++: nel
    res0: cats.data.NonEmptyList[Int] = NonEmptyList(-1, 0, 1, 2, 3)
  5. def :+[AA >: A](a: AA): NonEmptyList[AA]

    Alias for append

    Alias for append

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3)
    scala> nel :+ 4
    res0: cats.data.NonEmptyList[Int] = NonEmptyList(1, 2, 3, 4)
  6. def ::[AA >: A](a: AA): NonEmptyList[AA]
  7. def :::[AA >: A](other: NonEmptyList[AA]): NonEmptyList[AA]

    Alias for concatNel

    Alias for concatNel

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3)
    scala> nel ::: NonEmptyList.of(4, 5)
    res0: cats.data.NonEmptyList[Int] = NonEmptyList(1, 2, 3, 4, 5)
  8. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def ===[AA >: A](o: NonEmptyList[AA])(implicit AA: Eq[AA]): Boolean
  10. def append[AA >: A](a: AA): NonEmptyList[AA]
    Definition Classes
    NonEmptyList → NonEmptyCollection
  11. def appendList[AA >: A](other: List[AA]): NonEmptyList[AA]

    Alias for concat

    Alias for concat

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3)
    scala> nel.appendList(List(4, 5))
    res0: cats.data.NonEmptyList[Int] = NonEmptyList(1, 2, 3, 4, 5)
  12. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  13. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  14. def coflatMap[B](f: (NonEmptyList[A]) => B): NonEmptyList[B]
  15. def collect[B](pf: PartialFunction[A, B]): List[B]

    Builds a new List by applying a partial function to all the elements from this NonEmptyList on which the function is defined

    Builds a new List by applying a partial function to all the elements from this NonEmptyList on which the function is defined

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3, 4, 5)
    scala> nel.collect { case v if v < 3 => v }
    res0: scala.collection.immutable.List[Int] = List(1, 2)
    scala> nel.collect {
         |  case v if v % 2 == 0 => "even"
         |  case _ => "odd"
         | }
    res1: scala.collection.immutable.List[String] = List(odd, even, odd, even, odd)
    Definition Classes
    NonEmptyList → NonEmptyCollection
  16. def collectFirst[B](pf: PartialFunction[A, B]): Option[B]

    Find the first element matching the partial function, if one exists

    Find the first element matching the partial function, if one exists

    Definition Classes
    NonEmptyList → NonEmptyCollection
  17. def concat[AA >: A](other: List[AA]): NonEmptyList[AA]
  18. def concatNel[AA >: A](other: NonEmptyList[AA]): NonEmptyList[AA]

    Append another NonEmptyList

  19. def distinct[AA >: A](implicit O: Order[AA]): NonEmptyList[AA]

    Remove duplicates.

    Remove duplicates. Duplicates are checked using Order[_] instance.

    Definition Classes
    NonEmptyList → NonEmptyCollection
  20. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. def exists(p: (A) => Boolean): Boolean

    Check whether at least one element satisfies the predicate

    Check whether at least one element satisfies the predicate

    Definition Classes
    NonEmptyList → NonEmptyCollection
  22. def filter(p: (A) => Boolean): List[A]

    Remove elements not matching the predicate

    Remove elements not matching the predicate

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3, 4, 5)
    scala> nel.filter(_ < 3)
    res0: scala.collection.immutable.List[Int] = List(1, 2)
    Definition Classes
    NonEmptyList → NonEmptyCollection
  23. def filterNot(p: (A) => Boolean): List[A]

    Remove elements matching the predicate

    Remove elements matching the predicate

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3, 4, 5)
    scala> nel.filterNot(_ < 3)
    res0: scala.collection.immutable.List[Int] = List(3, 4, 5)
    Definition Classes
    NonEmptyList → NonEmptyCollection
  24. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  25. def find(p: (A) => Boolean): Option[A]

    Find the first element matching the predicate, if one exists

    Find the first element matching the predicate, if one exists

    Definition Classes
    NonEmptyList → NonEmptyCollection
  26. def flatMap[B](f: (A) => NonEmptyList[B]): NonEmptyList[B]
  27. def foldLeft[B](b: B)(f: (B, A) => B): B

    Left-associative fold on the structure using f.

    Left-associative fold on the structure using f.

    Definition Classes
    NonEmptyList → NonEmptyCollection
  28. def foldRight[B](lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B]

    Right-associative fold on the structure using f.

  29. def forall(p: (A) => Boolean): Boolean

    Check whether all elements satisfy the predicate

    Check whether all elements satisfy the predicate

    Definition Classes
    NonEmptyList → NonEmptyCollection
  30. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  31. def groupBy[B](f: (A) => B)(implicit B: Order[B]): SortedMap[B, NonEmptyList[A]]

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given mapping function.

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given mapping function.

    scala> import scala.collection.immutable.SortedMap
    scala> import cats.data.NonEmptyList
    scala> import cats.syntax.all._
    scala> val nel = NonEmptyList.of(12, -2, 3, -5)
    scala> val expectedResult = SortedMap(false -> NonEmptyList.of(-2, -5), true -> NonEmptyList.of(12, 3))
    scala> val result = nel.groupBy(_ >= 0)
    scala> result === expectedResult
    res0: Boolean = true
  32. def groupByNem[B](f: (A) => B)(implicit B: Order[B]): NonEmptyMap[B, NonEmptyList[A]]

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given mapping function.

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given mapping function.

    scala> import cats.data.{NonEmptyList, NonEmptyMap}
    scala> import cats.syntax.all._
    scala> val nel = NonEmptyList.of(12, -2, 3, -5)
    scala> val expectedResult = NonEmptyMap.of(false -> NonEmptyList.of(-2, -5), true -> NonEmptyList.of(12, 3))
    scala> val result = nel.groupByNem(_ >= 0)
    scala> result === expectedResult
    res0: Boolean = true
    Definition Classes
    NonEmptyList → NonEmptyCollection
  33. def groupMap[K, B](key: (A) => K)(f: (A) => B)(implicit K: Order[K]): SortedMap[K, NonEmptyList[B]]

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function.

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function. And each element in a group is transformed into a value of type B using the mapping function.

    scala> import scala.collection.immutable.SortedMap
    scala> import cats.data.NonEmptyList
    scala> import cats.syntax.all._
    scala> val nel = NonEmptyList.of(12, -2, 3, -5)
    scala> val expectedResult = SortedMap(false -> NonEmptyList.of("-2", "-5"), true -> NonEmptyList.of("12", "3"))
    scala> val result = nel.groupMap(_ >= 0)(_.toString)
    scala> result === expectedResult
    res0: Boolean = true
  34. def groupMapNem[K, B](key: (A) => K)(f: (A) => B)(implicit K: Order[K]): NonEmptyMap[K, NonEmptyList[B]]

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function.

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function. And each element in a group is transformed into a value of type B using the mapping function.

    scala> import cats.data.{NonEmptyList, NonEmptyMap}
    scala> import cats.syntax.all._
    scala> val nel = NonEmptyList.of(12, -2, 3, -5)
    scala> val expectedResult = NonEmptyMap.of(false -> NonEmptyList.of("-2", "-5"), true -> NonEmptyList.of("12", "3"))
    scala> val result = nel.groupMapNem(_ >= 0)(_.toString)
    scala> result === expectedResult
    res0: Boolean = true
  35. def groupMapReduce[K, B](key: (A) => K)(f: (A) => B)(implicit K: Order[K], B: Semigroup[B]): SortedMap[K, B]

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function.

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function. Then each element in a group is transformed into a value of type B using the mapping function. And finally they are all reduced into a single value using their Semigroup.

    scala> import scala.collection.immutable.SortedMap
    scala> import cats.data.NonEmptyList
    scala> import cats.syntax.all._
    scala> val nel = NonEmptyList.of("Hello", "World", "Goodbye", "World")
    scala> val expectedResult = SortedMap("goodbye" -> 1, "hello" -> 1, "world" -> 2)
    scala> val result = nel.groupMapReduce(_.trim.toLowerCase)(_ => 1)
    scala> result === expectedResult
    res0: Boolean = true
  36. def groupMapReduceNem[K, B](key: (A) => K)(f: (A) => B)(implicit K: Order[K], B: Semigroup[B]): NonEmptyMap[K, B]

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function.

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function. Then each element in a group is transformed into a value of type B using the mapping function. And finally they are all reduced into a single value using their Semigroup.

    scala> import cats.data.{NonEmptyList, NonEmptyMap}
    scala> import cats.syntax.all._
    scala> val nel = NonEmptyList.of("Hello", "World", "Goodbye", "World")
    scala> val expectedResult = NonEmptyMap.of("goodbye" -> 1, "hello" -> 1, "world" -> 2)
    scala> val result = nel.groupMapReduceNem(_.trim.toLowerCase)(_ => 1)
    scala> result === expectedResult
    res0: Boolean = true
  37. def groupMapReduceWith[K, B](key: (A) => K)(f: (A) => B)(combine: (B, B) => B)(implicit K: Order[K]): SortedMap[K, B]

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function.

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function. Then each element in a group is transformed into a value of type B using the mapping function. And finally they are all reduced into a single value using the provided combine function.

    scala> import scala.collection.immutable.SortedMap
    scala> import cats.data.NonEmptyList
    scala> import cats.syntax.all._
    scala> val nel = NonEmptyList.of("Hello", "World", "Goodbye", "World")
    scala> val expectedResult = SortedMap("goodbye" -> 1, "hello" -> 1, "world" -> 2)
    scala> val result = nel.groupMapReduceWith(_.trim.toLowerCase)(_ => 1)(_ + _)
    scala> result === expectedResult
    res0: Boolean = true
  38. def groupMapReduceWithNem[K, B](key: (A) => K)(f: (A) => B)(combine: (B, B) => B)(implicit K: Order[K]): NonEmptyMap[K, B]

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function.

    Groups elements inside this NonEmptyList according to the Order of the keys produced by the given key function. Then each element in a group is transformed into a value of type B using the mapping function. And finally they are all reduced into a single value using the provided combine function.

    scala> import cats.data.{NonEmptyList, NonEmptyMap}
    scala> import cats.syntax.all._
    scala> val nel = NonEmptyList.of("Hello", "World", "Goodbye", "World")
    scala> val expectedResult = NonEmptyMap.of("goodbye" -> 1, "hello" -> 1, "world" -> 2)
    scala> val result = nel.groupMapReduceWithNem(_.trim.toLowerCase)(_ => 1)(_ + _)
    scala> result === expectedResult
    res0: Boolean = true
  39. def grouped(size: Int): Iterator[NonEmptyList[A]]

    Partitions elements in fixed size NonEmptyLists.

    Partitions elements in fixed size NonEmptyLists.

    scala> import cats.data.NonEmptyList
    scala> import cats.syntax.all._
    scala> val nel = NonEmptyList.of(12, -2, 3, -5)
    scala> val expectedResult = List(NonEmptyList.of(12, -2), NonEmptyList.of(3, -5))
    scala> val result = nel.grouped(2)
    scala> result.toList === expectedResult
    res0: Boolean = true
    Definition Classes
    NonEmptyList → NonEmptyCollection
  40. val head: A
    Definition Classes
    NonEmptyList → NonEmptyCollection
  41. def init: List[A]

    Selects all elements except the last

    Selects all elements except the last

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3, 4, 5)
    scala> nel.init
    res0: scala.collection.immutable.List[Int] = List(1, 2, 3, 4)
    Definition Classes
    NonEmptyList → NonEmptyCollection
  42. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  43. final def iterator: Iterator[A]
    Definition Classes
    NonEmptyList → NonEmptyCollection
  44. def last: A

    Selects the last element

    Selects the last element

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3, 4, 5)
    scala> nel.last
    res0: Int = 5
    Definition Classes
    NonEmptyList → NonEmptyCollection
  45. def length: Int
  46. def map[B](f: (A) => B): NonEmptyList[B]

    Applies f to all the elements of the structure

    Applies f to all the elements of the structure

    Definition Classes
    NonEmptyList → NonEmptyCollection
  47. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  48. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  49. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  50. def prepend[AA >: A](a: AA): NonEmptyList[AA]
    Definition Classes
    NonEmptyList → NonEmptyCollection
  51. def prependList[AA >: A](other: List[AA]): NonEmptyList[AA]

    Prepend another List

    Prepend another List

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3)
    scala> val list = List(-1, 0)
    scala> nel.prependList(list)
    res0: cats.data.NonEmptyList[Int] = NonEmptyList(-1, 0, 1, 2, 3)
  52. def productElementNames: Iterator[String]
    Definition Classes
    Product
  53. def reduce[AA >: A](implicit S: Semigroup[AA]): AA

    Reduce using the Semigroup of AA.

    Reduce using the Semigroup of AA.

    Definition Classes
    NonEmptyList → NonEmptyCollection
  54. def reduceLeft[AA >: A](f: (AA, AA) => AA): AA

    Left-associative reduce using f.

  55. def reverse: NonEmptyList[A]

    Reverse this NonEmptyList.

    Reverse this NonEmptyList.

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3)
    scala> nel.reverse
    res0: cats.data.NonEmptyList[Int] = NonEmptyList(3, 2, 1)
    Definition Classes
    NonEmptyList → NonEmptyCollection
  56. def show[AA >: A](implicit AA: Show[AA]): String
    Definition Classes
    NonEmptyList → NonEmptyCollection
  57. def size: Int

    The size of this NonEmptyList

    The size of this NonEmptyList

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3, 4, 5)
    scala> nel.size
    res0: Int = 5
  58. def sortBy[B](f: (A) => B)(implicit B: Order[B]): NonEmptyList[A]

    Sorts this NonEmptyList according to an Order on transformed B from A

    Sorts this NonEmptyList according to an Order on transformed B from A

    scala> import cats.data.NonEmptyList
    scala> import cats.instances.int._
    scala> val nel = NonEmptyList.of(('a', 4), ('z', 1), ('e', 22))
    scala> nel.sortBy(_._2)
    res0: cats.data.NonEmptyList[(Char, Int)] = NonEmptyList((z,1), (a,4), (e,22))
    Definition Classes
    NonEmptyList → NonEmptyCollection
  59. def sorted[AA >: A](implicit AA: Order[AA]): NonEmptyList[AA]

    Sorts this NonEmptyList according to an Order

    Sorts this NonEmptyList according to an Order

    scala> import cats.data.NonEmptyList
    scala> import cats.instances.int._
    scala> val nel = NonEmptyList.of(12, 4, 3, 9)
    scala> nel.sorted
    res0: cats.data.NonEmptyList[Int] = NonEmptyList(3, 4, 9, 12)
    Definition Classes
    NonEmptyList → NonEmptyCollection
  60. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  61. val tail: List[A]
    Definition Classes
    NonEmptyList → NonEmptyCollection
  62. def take(n: Int): List[A]

    Returns the first n elements of this NonEmptyList as a List.

    Returns the first n elements of this NonEmptyList as a List.

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3, 4, 5)
    scala> nel.take(3)
    res0: scala.collection.immutable.List[Int] = List(1, 2, 3)
  63. def toList: List[A]

    Return the head and tail into a single list

    Return the head and tail into a single list

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of(1, 2, 3, 4, 5)
    scala> nel.toList
    res0: scala.collection.immutable.List[Int] = List(1, 2, 3, 4, 5)
  64. def toNem[T, U](implicit ev: <:<[A, (T, U)], order: Order[T]): NonEmptyMap[T, U]

    Creates new NonEmptyMap, similarly to List#toMap from scala standard library.

    Creates new NonEmptyMap, similarly to List#toMap from scala standard library.

    scala> import cats.data.{NonEmptyList, NonEmptyMap}
    scala> import cats.syntax.all._
    scala> val nel = NonEmptyList((0, "a"), List((1, "b"),(0, "c"), (2, "d")))
    scala> val expectedResult = NonEmptyMap.of(0 -> "c", 1 -> "b", 2 -> "d")
    scala> val result = nel.toNem
    scala> result === expectedResult
    res0: Boolean = true
    Definition Classes
    NonEmptyList → NonEmptyCollection
  65. def toNes[B >: A](implicit order: Order[B]): NonEmptySet[B]

    Creates new NonEmptySet, similarly to List#toSet from scala standard library.

    Creates new NonEmptySet, similarly to List#toSet from scala standard library.

    scala> import cats.data._
    scala> import cats.instances.int._
    scala> val nel = NonEmptyList(1, List(2,2,3,4))
    scala> nel.toNes
    res0: cats.data.NonEmptySet[Int] = TreeSet(1, 2, 3, 4)
    Definition Classes
    NonEmptyList → NonEmptyCollection
  66. def toNev[B >: A]: NonEmptyVector[B]

    Creates new NonEmptyVector, similarly to List#toVector from scala standard library.

    Creates new NonEmptyVector, similarly to List#toVector from scala standard library.

    scala> import cats.data._
    scala> import cats.instances.int._
    scala> val nel = NonEmptyList(1, List(2,3,4))
    scala> val expectedResult = NonEmptyVector.fromVectorUnsafe(Vector(1,2,3,4))
    scala> val result = nel.toNev
    scala> result === expectedResult
    res0: Boolean = true
  67. def toString(): String
    Definition Classes
    NonEmptyList → AnyRef → Any
  68. def traverse[G[_], B](f: (A) => G[B])(implicit G: Applicative[G]): G[NonEmptyList[B]]
  69. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  70. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  71. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  72. def zip[B](nel: NonEmptyList[B]): NonEmptyList[(A, B)]

    Zips this NonEmptyList with another NonEmptyList and returns the pairs of elements.

    Zips this NonEmptyList with another NonEmptyList and returns the pairs of elements.

    scala> import cats.data.NonEmptyList
    scala> val as = NonEmptyList.of(1, 2, 3)
    scala> val bs = NonEmptyList.of("A", "B", "C")
    scala> as.zip(bs)
    res0: cats.data.NonEmptyList[(Int, String)] = NonEmptyList((1,A), (2,B), (3,C))
  73. def zipWith[B, C](b: NonEmptyList[B])(f: (A, B) => C): NonEmptyList[C]

    Zips this NonEmptyList with another NonEmptyList and applies a function for each pair of elements.

    Zips this NonEmptyList with another NonEmptyList and applies a function for each pair of elements.

    scala> import cats.data.NonEmptyList
    scala> val as = NonEmptyList.of(1, 2, 3)
    scala> val bs = NonEmptyList.of("A", "B", "C")
    scala> as.zipWith(bs)(_.toString + _)
    res0: cats.data.NonEmptyList[String] = NonEmptyList(1A, 2B, 3C)
    Definition Classes
    NonEmptyList → NonEmptyCollection
  74. def zipWithIndex: NonEmptyList[(A, Int)]

    Zips each element of this NonEmptyList with its index.

    Zips each element of this NonEmptyList with its index.

    scala> import cats.data.NonEmptyList
    scala> val nel = NonEmptyList.of("a", "b", "c")
    scala> nel.zipWithIndex
    res0: cats.data.NonEmptyList[(String, Int)] = NonEmptyList((a,0), (b,1), (c,2))
    Definition Classes
    NonEmptyList → NonEmptyCollection

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from NonEmptyCollection[A, List, NonEmptyList]

Inherited from AnyRef

Inherited from Any

Ungrouped