Skip to content

Instantly share code, notes, and snippets.

@trane
Last active September 18, 2015 17:13
Show Gist options
  • Select an option

  • Save trane/642b2669d8befe640887 to your computer and use it in GitHub Desktop.

Select an option

Save trane/642b2669d8befe640887 to your computer and use it in GitHub Desktop.
// first, we need to create a way to describe a Path in a generic way
import shapeless._, labelled._, record._, syntax.singleton._
import com.twitter.finagle.httpx.path
// this describes the to and from, giving the compiler a way to side step type erasure
// i'm using path.Path to disambiguate a "Path" which is included in the shapeless imports
// in fact, if we supply this in the package object of the module we are using we will have implicit access to it :)
implicit object pathGeneric extends LabelledGeneric[path.Path] {
type Repr = Record.`'str -> String`.T // create a witness/record for this symbol 'str
def from(r: Repr): path.Path = path.Path(r('str)) // define a way to create a path from this Record
def to(t: path.Path): Repr = ('str ->> t.toString) :: HNil // define a way to create a Record/HList from a Path
}
// next we just use circe like we always would :)
import io.circe._, io.circe.generic.auto._, io.circe.jawn._, io.circe.syntax._
decode[path.Path](path.Path("/hello/world").asJson.toString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment