Skip to content

Commit

Permalink
Merge pull request #1514 from xavier-fernandez/NEV_filterNot
Browse files Browse the repository at this point in the history
Implement NonEmptyVector#filterNot
  • Loading branch information
kailuowang authored Jan 4, 2017
2 parents 52b1057 + 2a7e900 commit 39c3e48
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
23 changes: 21 additions & 2 deletions core/src/main/scala/cats/data/NonEmptyVector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,29 @@ final class NonEmptyVector[A] private (val toVector: Vector[A]) extends AnyVal {
def tail: Vector[A] = toVector.tail

/**
* remove elements not matching the predicate
*/
* Remove elements not matching the predicate
*
* {{{
* scala> import cats.data.NonEmptyVector
* scala> val nev = NonEmptyVector.of(1, 2, 3, 4, 5)
* scala> nev.filter(_ < 3)
* res0: scala.collection.immutable.Vector[Int] = Vector(1, 2)
* }}}
*/
def filter(f: A => Boolean): Vector[A] = toVector.filter(f)

/**
* Remove elements matching the predicate
*
* {{{
* scala> import cats.data.NonEmptyVector
* scala> val nev = NonEmptyVector.of(1, 2, 3, 4, 5)
* scala> nev.filterNot(_ < 3)
* res0: scala.collection.immutable.Vector[Int] = Vector(3, 4, 5)
* }}}
*/
def filterNot(f: A => Boolean): Vector[A] = toVector.filterNot(f)

/**
* Alias for [[concat]]
*/
Expand Down
7 changes: 7 additions & 0 deletions tests/src/test/scala/cats/tests/NonEmptyVectorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ class NonEmptyVectorTests extends CatsSuite {
}
}

test("NonEmptyVector#filterNot is consistent with Vector#filterNot") {
forAll { (nonEmptyVector: NonEmptyVector[Int], p: Int => Boolean) =>
val vector = nonEmptyVector.toVector
nonEmptyVector.filterNot(p) should === (vector.filterNot(p))
}
}

test("NonEmptyVector#find is consistent with Vector#find") {
forAll { (nonEmptyVector: NonEmptyVector[Int], p: Int => Boolean) =>
val vector = nonEmptyVector.toVector
Expand Down

0 comments on commit 39c3e48

Please sign in to comment.