Skip to content

Commit

Permalink
Add ::: to NonEmptyList (#1949)
Browse files Browse the repository at this point in the history
* Add ::: to NonEmptyList

* Add ++: to NEV and some doc to ::: in NEL

* Add doctest for NEL.::: and NEV.++:

* Use concatNel instead of concat

* Fix concat reference in scaladoc
  • Loading branch information
jcranky authored and kailuowang committed Nov 2, 2017
1 parent 9077383 commit 9912a8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/src/main/scala/cats/data/NonEmptyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ final case class NonEmptyList[+A](head: A, tail: List[A]) {
def prepend[AA >: A](a: AA): NonEmptyList[AA] =
NonEmptyList(a, head :: tail)

/**
* Alias for concat
*
* {{{
* 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)
* }}}
*/
def :::[AA >: A](other: NonEmptyList[AA]): NonEmptyList[AA] =
other.concatNel(this)

/**
* Remove elements not matching the predicate
*
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/scala/cats/data/NonEmptyVector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ final class NonEmptyVector[+A] private (val toVector: Vector[A]) extends AnyVal
*/
def ++[AA >: A](other: Vector[AA]): NonEmptyVector[AA] = concat(other)

/**
* Append this NEV to another NEV, producing a new `NonEmptyVector`.
*
* {{{
* scala> import cats.data.NonEmptyVector
* scala> val nev = NonEmptyVector.of(1, 2, 3)
* scala> nev ++: NonEmptyVector.of(4, 5)
* res0: cats.data.NonEmptyVector[Int] = NonEmptyVector(1, 2, 3, 4, 5)
* }}}
*/
def ++:[AA >: A](other: NonEmptyVector[AA]): NonEmptyVector[AA] = other.concatNev(this)

/**
* Append another `Vector` to this, producing a new `NonEmptyVector`.
*/
Expand Down

0 comments on commit 9912a8e

Please sign in to comment.