Last active
December 18, 2015 05:59
-
-
Save soc/5737097 to your computer and use it in GitHub Desktop.
This file contains 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
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 => | |
current.tl = Nil | |
return | |
case a => | |
val list: ::[B] = new ::(a.asInstanceOf[B], Nil) | |
current.tl = 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 | |
out.writeObject(ListSerializeEnd) | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How? Where?