Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
! routing: remove layer of *Aux classes by type aliases for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudolph committed Oct 14, 2013
1 parent 979fc31 commit d86cb80
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 31 deletions.
Expand Up @@ -73,22 +73,18 @@ trait AnyParamDefMagnet2[T] {
}

object AnyParamDefMagnet2 {
import FieldDefMagnet2.FieldDefMagnetAux
import ParamDefMagnet2.ParamDefMagnetAux

implicit def forTuple[T <: Product, L <: HList, Out](implicit hla: HListerAux[T, L],
apdma: AnyParamDefMagnetAux[L]) =
apdma: AnyParamDefMagnet2[L]) =
new AnyParamDefMagnet2[T] {
def apply(value: T) = apdma(hla(value))
type Out = apdma.Out
}
}

trait AnyParamDefMagnetAux[L] {
type Out
def apply(value: L): Out
}

object AnyParamDefMagnetAux {
implicit def forHList[L <: HList](implicit f: LeftFolder[L, Directive0, MapReduce.type]) =
new AnyParamDefMagnetAux[L] {
new AnyParamDefMagnet2[L] {
type Out = f.Out
def apply(value: L) = {
value.foldLeft(BasicDirectives.noop)(MapReduce)
Expand Down
Expand Up @@ -53,22 +53,15 @@ trait FieldDefMagnet2[T] {
type Out
def apply(value: T): Out
}
object FieldDefMagnet2 {
implicit def apply[A, B](implicit fdma: FieldDefMagnetAux[A, B]) = new FieldDefMagnet2[A] {
type Out = B
def apply(value: A) = fdma(value)
}
}

trait FieldDefMagnetAux[A, B] extends (A B)
object FieldDefMagnet2 extends ToNameReceptaclePimps {
type FieldDefMagnetAux[A, B] = FieldDefMagnet2[A] { type Out = B }
def FieldDefMagnetAux[A, B](f: A B) = new FieldDefMagnet2[A] { type Out = B; def apply(value: A) = f(value) }

object FieldDefMagnetAux extends ToNameReceptaclePimps {
import spray.httpx.unmarshalling.{ FromRequestUnmarshaller UM, FormFieldConverter FFC, FromBodyPartOptionUnmarshaller FBPOU, _ }
import BasicDirectives._
import RouteDirectives._

def apply[A, B](f: A B) = new FieldDefMagnetAux[A, B] { def apply(value: A) = f(value) }

/************ "regular" field extraction ******************/

def extractField[A, B](f: A Directive1[B]) = FieldDefMagnetAux[A, Directive1[B]](f)
Expand Down Expand Up @@ -113,4 +106,4 @@ object FieldDefMagnetAux extends ToNameReceptaclePimps {
implicit def from[T, LA <: HList, LB <: HList, Out <: HList](implicit fdma: FieldDefMagnetAux[T, Directive[LB]], ev: PrependAux[LA, LB, Out]) =
at[Directive[LA], T] { (a, t) a & fdma(t) }
}
}
}
Expand Up @@ -79,22 +79,15 @@ trait ParamDefMagnet2[T] {
type Out
def apply(value: T): Out
}
object ParamDefMagnet2 {
implicit def apply[A, B](implicit pdma: ParamDefMagnetAux[A, B]) = new ParamDefMagnet2[A] {
type Out = B
def apply(value: A) = pdma(value)
}
}

trait ParamDefMagnetAux[A, B] extends (A B)
object ParamDefMagnet2 {
type ParamDefMagnetAux[A, B] = ParamDefMagnet2[A] { type Out = B }
def ParamDefMagnetAux[A, B](f: A B) = new ParamDefMagnet2[A] { type Out = B; def apply(value: A) = f(value) }

object ParamDefMagnetAux {
import spray.httpx.unmarshalling.{ FromStringOptionDeserializer FSOD, _ }
import BasicDirectives._
import RouteDirectives._

def apply[A, B](f: A B) = new ParamDefMagnetAux[A, B] { def apply(value: A) = f(value) }

/************ "regular" parameter extraction ******************/

private def extractParameter[A, B](f: A Directive1[B]) = ParamDefMagnetAux[A, Directive1[B]](f)
Expand Down Expand Up @@ -152,4 +145,4 @@ object ParamDefMagnetAux {
implicit def from[T, LA <: HList, LB <: HList, Out <: HList](implicit pdma: ParamDefMagnetAux[T, Directive[LB]], ev: PrependAux[LA, LB, Out]) =
at[Directive[LA], T] { (a, t) a & pdma(t) }
}
}
}

0 comments on commit d86cb80

Please sign in to comment.