Created
December 30, 2016 21:18
-
-
Save Sciss/79922fcf3f18d9bb9d1ab703db92d0c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import scala.collection.{GenTraversableOnce, LinearSeq, LinearSeqLike, mutable} | |
import scala.collection.generic.CanBuildFrom | |
object Message { | |
def apply[A](args: A*): Message[A] = new Message(args) | |
def newBuilder[A]: mutable.Builder[A, Message[A]] = | |
new mutable.ArrayBuffer[A].mapResult(buf => new Message(buf)) | |
implicit def builderFactory[A]: CanBuildFrom[Any, A, Message[A]] = new CanBuildFrom[Any, A, Message[A]] { | |
def apply() = Message.newBuilder[A] | |
def apply(a: Any) = apply() | |
} | |
} | |
class Message[A] private (args: Seq[A]) | |
extends LinearSeq[A] with LinearSeqLike[A, Message[A]] { | |
type Repr = Message[A] | |
def apply(idx: Int): A = args(idx) | |
def length: Int = args.length | |
override def iterator: Iterator[A] = args.iterator | |
override def newBuilder: mutable.Builder[A, Message[A]] = Message.newBuilder | |
} | |
Message(1, 2, 3) ++ Message(4, 5, 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment