Skip to content

Commit

Permalink
add append method to NEL (#2416)
Browse files Browse the repository at this point in the history
* add append method to NEL

* add doctest for :+
  • Loading branch information
julien-truffaut authored and Luka Jacobowitz committed Aug 16, 2018
1 parent a2a55b5 commit d4db711
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/src/main/scala/cats/data/NonEmptyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ final case class NonEmptyList[+A](head: A, tail: List[A]) {
def prepend[AA >: A](a: AA): NonEmptyList[AA] =
NonEmptyList(a, head :: tail)

/**
* 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)
* }}}
*/
def :+[AA >: A](a: AA): NonEmptyList[AA] =
append(a)

def append[AA >: A](a: AA): NonEmptyList[AA] =
NonEmptyList(head, tail :+ a)

/**
* Alias for concatNel
*
Expand Down

0 comments on commit d4db711

Please sign in to comment.