Created
March 29, 2011 19:06
-
-
Save dhinojosa/893021 to your computer and use it in GitHub Desktop.
Mucking with NonEmptyList discussing with friend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait NonEmptyList[+A] { | |
val head: A | |
val tail: List[A] | |
import Scalaz._ | |
def <::[B >: A](b: B): NonEmptyList[B] = nel(b, head :: tail) | |
import collection.mutable.ListBuffer | |
def <:::[B >: A](bs: List[B]): NonEmptyList[B] = { //Scary | |
val b = new ListBuffer[B] | |
b ++= bs | |
b += head | |
b ++= tail | |
val bb = b.toList | |
nel(bb.head, bb.tail) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment