Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement NonEmptyVector#filterNot #1514

Merged
merged 1 commit into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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