Skip to content

Commit

Permalink
Add tailOption for std List
Browse files Browse the repository at this point in the history
  • Loading branch information
adelbertc committed Apr 19, 2014
1 parent a4db99e commit cfcdda8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/main/scala/scalaz/std/List.scala
Expand Up @@ -136,6 +136,11 @@ trait ListFunctions {
intersperse0(Nil, as).reverse
}

final def tailOption[A](as: List[A]): Option[List[A]] = as match {
case Nil => None
case _ :: t => Some(t)
}

/** [[scala.Nil]] with a sometimes more convenient type */
final def nil[A]: List[A] = Nil

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/scala/scalaz/syntax/std/ListOps.scala
Expand Up @@ -8,6 +8,8 @@ import scalaz.std.{list => l}
final class ListOps[A](self: List[A]) {
final def intersperse(a: A): List[A] = l.intersperse(self, a)

final def tailOption: Option[List[A]] = l.tailOption(self)

final def toNel: Option[NonEmptyList[A]] = l.toNel(self)

final def toZipper: Option[Zipper[A]] = l.toZipper(self)
Expand Down

0 comments on commit cfcdda8

Please sign in to comment.