Skip to content

Instantly share code, notes, and snippets.

@ismagin
Created February 1, 2018 09:05
Show Gist options
  • Save ismagin/97e47432416f971a05fee09aafcba3fb to your computer and use it in GitHub Desktop.
Save ismagin/97e47432416f971a05fee09aafcba3fb to your computer and use it in GitHub Desktop.
package ex
import scodec.{Codec, codecs}
import scodec.codecs.{Discriminated, uint8}
object ASD extends App {
sealed trait Expr
case class INT(i: Int) extends Expr
case class SUM(i1: Expr, i2: Expr) extends Expr
import codecs.implicits._
implicit def d = Discriminated[Expr, Int](uint8)
implicit def dInt = d.bind[INT](0)
implicit def dSum = d.bind[SUM](1)
val codec = Codec[Expr]
val term = (1 to 100000).foldLeft[Expr](INT(0))((acc, _) => SUM(acc, INT(1)))
codec.encode(term)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment