Created
February 28, 2014 23:14
-
-
Save b-studios/9281989 to your computer and use it in GitHub Desktop.
Simple implementation of snoc lists
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
trait SnocList[+T] { | |
def <> [S >: T](el: S) = Snoc(this, el) | |
} | |
case class Snoc[+T](init: SnocList[T], el: T) extends SnocList[T] | |
case object Empty extends SnocList[Nothing] | |
// usage: | |
// scala> Empty <> 1 <> 2 <> 3 <> 4 | |
// res0: Snoc[Int] = Snoc(Snoc(Snoc(Snoc(Empty,1),2),3),4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment