Skip to content

Commit

Permalink
Add :: method to NonEmptyList
Browse files Browse the repository at this point in the history
  • Loading branch information
ceedubs committed Jul 27, 2016
1 parent c8fcaf0 commit cfdd085
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/main/scala/cats/data/NonEmptyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ final case class NonEmptyList[A](head: A, tail: List[A]) {
def flatMap[B](f: A => NonEmptyList[B]): NonEmptyList[B] =
f(head) ++ tail.flatMap(f andThen (_.toList))

def ::(a: A): NonEmptyList[A] = NonEmptyList(a, head :: tail)

/**
* remove elements not matching the predicate
*/
Expand Down
6 changes: 6 additions & 0 deletions tests/src/test/scala/cats/tests/NonEmptyListTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ class NonEmptyListTests extends CatsSuite {
NonEmptyList.fromListUnsafe(List.empty[Int])
}
}

test(":: consistent with List") {
forAll { (nel: NonEmptyList[Int], i: Int) =>
(i :: nel).toList should === (i :: nel.toList)
}
}
}

class ReducibleNonEmptyListCheck extends ReducibleCheck[NonEmptyList]("NonEmptyList") {
Expand Down

0 comments on commit cfdd085

Please sign in to comment.