scala - Hoes do Spray Parameters work? -


i'm trying wrap head around how spray has implemented directives, , in particular parameter extraction dsl.

i understand magnet pattern (barely) stuck on how paramdefmagnet , paramdefmagnet2 work together.

def parameter(pdm: paramdefmagnet): pdm.out = pdm()  trait paramdefmagnet {   type out   def apply(): out }  trait paramdefmagnet2[t] {   type out   def apply(value: t): out }  type paramdefmagnetaux[a, b] = paramdefmagnet2[a] { type out = b }   def paramdefmagnetaux[a, b](f: ⇒ b) = new paramdefmagnet2[a] { type out = b; def apply(value: a) = f(value) } 

i'm trying work out how paramdefmanget2 implicitly converted paramdefmagnet the below implicit method.

object paramdefmagnet {   implicit def apply[t](value: t)(implicit pdm2: paramdefmagnet2[t]) = new paramdefmagnet {     type out = pdm2.out     def apply() = pdm2(value)   } } 

if call parameter("name"), how "name" implicitly converted paramdefmagnet? , if converts paramdefmagnet2 first, value: t come in order convert paramdefmagnet?

so after digging around examples, think i've got bottom of how parameter function works:

def parameter(pdm: paramdefmagnet): pdm.out = pdm() 

an example extracting parameter of type string:

val p: directive1[string] = parameter("name")  // can apply function extracted name p { name =>     // stuff } 

spray uses bunch of implicit conversions basically, if have string , string => directive1[string], can construct () => directive1[string]:

// our string => directive1[string] val pdm2: paramdefmagnet2[string] { type out = directive1[string] } = paramdefmagnet2.fromstring  // our () => directive1[string] val pdm: paramdefmagnet { type out = directive1[string] } = new paramdefmagnet {   type out = directive1[string]   def apply() = pdm2("name") } val directive: directive1[string] = pdm() // equivalent to: val directive2: directive1[string] = parameter("name") 

all of constitutes simple parameter("name") call:

val p: directive1[string] = parameter("name") 

for how directive1[string] applied in dsl-ey way, see how directives work in spray?


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -