Skip to content

Instantly share code, notes, and snippets.

@b-studios
Created February 28, 2014 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b-studios/9281989 to your computer and use it in GitHub Desktop.
Save b-studios/9281989 to your computer and use it in GitHub Desktop.
Simple implementation of snoc lists
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