Create a gist now

Instantly share code, notes, and snippets.

@soc /::.scala
Last active Dec 18, 2015

final case class ::[B](private var hd: B, private[scala] var tl: List[B]) extends List[B]
override def head: B = hd
override def tail: List[B] = tl
override def isEmpty: Boolean = false
private def readObject(in: ObjectInputStream): Unit =
val firstObject = in.readObject()
hd = firstObject.asInstanceOf[B]
assert(hd != ListSerializeEnd)
var current: ::[B] = this
while true
do in.readObject match
case ListSerializeEnd => = Nil
case a =>
val list: ::[B] = new ::(a.asInstanceOf[B], Nil) = list
current = list
private def writeObject(out: ObjectOutputStream): Unit =
var xs: List[B] = this
while !xs.isEmpty
do out.writeObject(xs.head); xs = xs.tail
override def slice(from: Int, until: Int): List[A] =
val lo = scala.math.max(from, 0)
if until <= lo || isEmpty
then Nil
else this drop lo take (until - lo)

This comment has been minimized.

Show comment
Hide comment

pedrofurla Jul 3, 2013

How? Where?

How? Where?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment