Skip to content

Instantly share code, notes, and snippets.

View propensive's full-sized avatar

Jon Pretty propensive

View GitHub Profile
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.
scala> System.getProperty("user.timezone")
res0: String = ""
scala> new java.util.Date()
res1: java.util.Date = Mon May 12 12:49:35 CEST 2014
@propensive
propensive / matching.scala
Created July 24, 2014 00:25
Configurable JSON pattern matching in Rapture JSON 0.10
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import rapture.core._; import rapture.data._; import rapture.json._
import rapture.core._
import rapture.data._
import rapture.json._
scala> import jsonBackends.scalaJson._
@propensive
propensive / formatters.scala
Created August 2, 2014 14:43
Custom formatters in Rapture JSON
scala> import formatters.humanReadable
import formatters.humanReadable
scala> Json.format(json"""{ "foo": ["bar", "baz", 42] }""")
res0: String =
{
"foo": [
"bar",
"baz",
42
@propensive
propensive / repl.scala
Created November 17, 2014 08:41
Compile-time JSON syntax checking in Rapture JSON
Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.6.0_27).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import rapture.json._
import rapture.json._
scala> import jsonBackends.scalaJson._
import jsonBackends.scalaJson._
@propensive
propensive / diagnostics.repl
Created November 25, 2014 14:04
Better compile-time diagnostics when attempting to extract case classes from JSON
scala> case class Bar(file: java.io.File) // We can't extract a File
defined class Bar
scala> case class Foo(bar: Bar) // therefore we can't extract a Bar
defined class Foo
scala> json""{ "bar": { "file": "..." } }""".as[Foo]
Could not generate a Json extractor for case class Bar because a Json extractor for parameter `file' of type java.io.File could not be found
Could not generate a Json extractor for case class Foo because a Json extractor for parameter `bar' of type Bar could not be found
<console>:21: error: cannot extract type Foo from rapture.json.Json.
> sbt benchmark/run
<snip>
[info] Compiling 4 Scala sources to /home/jpretty/dev/github.com/non/jawn/benchmark/target/scala-2.11/classes...
[error] /home/jpretty/dev/github.com/non/jawn/benchmark/src/main/scala/jawn/Parboiled.scala:27: reference to ParserInput is ambiguous;
[error] it is imported twice in the same scope by
[error] import spray.json._
[error] and import org.parboiled2._
[error] class ParboiledParser(val input: ParserInput) extends Parser with StringBuilding {
package interpolate
import rapture.json._
import jsonBackends.jawn._
object Interpolation {
case class Forced(json: Json)
implicit def toForced[T: JsonSerializer](t: T): Forced = Forced(Json(t))
case class Instantiator[T]()
def instantiate[T](implicit inst: Instantiator[T]): T = null.asInstanceOf[T]
val x: String = instantiate
// error: could not find implicit for Instantiator[T]
implicit def inst1: Instantiator[String] = Instantiator[String]
implicit def inst2: Instantiator[Int] = Instantiator[Int]
val x: String = instantiate
// error: ambiguous implicits
@propensive
propensive / strap.scala
Last active August 29, 2015 14:12
Collection.strap
Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.6.0_27).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import rapture.core._
import rapture.core._
scala> List.strap(1, Some(2), None)
res0: List[Int] = List(1, 2)
Welcome to Scala version 2.11.4 (OpenJDK 64-Bit Server VM, Java 1.6.0_27).
Type in expressions to have them evaluated.
Type :help for more information.
scala> case class Foo[T](name: String)
defined class Foo
scala> implicit val stringFoo = Foo[String]("String")
stringFoo: Foo[String] = Foo(String)