public
Last active

  • Download Gist
::.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.