Skip to content

Instantly share code, notes, and snippets.

@propensive
propensive / jsonDefaults.scala
Created August 1, 2015 16:36
Rapture JSON support for case class defaults
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import rapture.json._
import rapture.json._
scala> import jsonBackends.jawn._
import jsonBackends.jawn._ // This also works with Play, Spray, Argonaut, JSON4S and Lift
@propensive
propensive / recursive.scala
Created August 1, 2015 16:49
Recursive case class extraction in Rapture JSON
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import rapture.json._
import rapture.json._
scala> import jsonBackends.spray._
import jsonBackends.spray._
@propensive
propensive / rapturejsonerrors.scala
Created August 6, 2015 08:08
Rapture JSON erorrs
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import rapture.json._
import rapture.json._
scala> import jsonBackends.jawn._
import jsonBackends.jawn._
@propensive
propensive / xmldemo.scala
Last active February 20, 2018 11:54
Really Basic Rapture XML basic demo
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import rapture.xml._
import rapture.xml._
scala> import xmlBackends.stdlib._
import xmlBackends.stdlib._
@propensive
propensive / tmatch.scala
Created January 27, 2016 21:40
Type Matching in Scala
scala> :paste
// Entering paste mode (ctrl-D to finish)
val fn = tmatch(
when[Int] { i => i + 1 }
when[String] { s => s.toInt }
when[Symbol] { s => 3.1415926 }
when[Double] { d => "You entered a double" }
)
Welcome to Scala 2.12.0-M5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions for evaluation. Or try :help.
scala> case class Foo(x: Int)
defined class Foo
scala> implicit def foo: Foo = Foo(1)
foo: Foo
scala> implicitly[Foo]
Welcome to Scala 2.12.0-M5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions for evaluation. Or try :help.
scala> case class Foo(x: Int)
defined class Foo
scala> object Bar {
| implicit val foo: Foo = Foo(1)
| object Baz {
| implicit val foo: Foo = Foo(2)
@propensive
propensive / derivation_benchmarks
Created November 22, 2017 23:37
Derivation benchmarks
magnolia/one:
00:01.388187 src/foo.scala
00:04.130835 src/magnolia/one.scala
00:01.339720 src/magnolia/one.scala
00:00.893572 src/magnolia/one.scala
00:00.640120 src/magnolia/one.scala
00:00.664193 src/magnolia/one.scala
00:00.608714 src/magnolia/one.scala
00:00.502048 src/magnolia/one.scala
00:00.497764 src/magnolia/one.scala
### Keybase proof
I hereby claim:
* I am propensive on github.
* I am propensive (https://keybase.io/propensive) on keybase.
* I have a public key ASArWRtQnt8y3AuDBYD0B3FsCtq6W4pRE0tAl6GhlZMAcAo
@propensive
propensive / DiffableDerivation.scala
Created December 23, 2018 05:18 — forked from Fristi/DiffableDerivation.scala
specs2 `Diffable` magnolia derivation
import magnolia.{CaseClass, Magnolia, SealedTrait}
import org.specs2.matcher.describe._
import scala.language.experimental.macros
object DiffableDerivation {
/** binds the Magnolia macro to this derivation object */
implicit def genDiffable[T]: Diffable[T] = macro Magnolia.gen[T]