Skip to content

Instantly share code, notes, and snippets.

@j3vanek
j3vanek / CompanionConstraints.scala
Created April 8, 2013 21:40
Statically typed companion reference.
object CompanionConstraint {
// prerequisites
type UpperBound[T] = T // for now; needs to be type macro ...
trait Companion[T <: { type Object }] { this: UpperBound[T#Object] => implicit def self = this }
def companion[T <: { type Object } : Companion]: UpperBound[T#Object] = implicitly[Companion[T]].self
// declarations
@j3vanek
j3vanek / ListSer.scala
Last active December 11, 2015 00:39 — forked from anonymous/ListSer.scala
List serialization which supports long lists, structural sharing and 2.9 serialization data. Added tests to check the structural sharing after deserialization. Simplified using closure. Split into 2 loops (lists, heads) to be breadth-first.
// package ...
import java.io._
object ListSer {
sealed abstract class List[+A] extends Serializable {
def isEmpty: Boolean
def head: A
def tail: List[A]