=htp add more explicit type annotations to implicit definitions

This commit is contained in:
Johannes Rudolph 2015-06-18 16:20:47 +02:00
parent b0ea8c935a
commit 10fb88e2bc
3 changed files with 9 additions and 7 deletions

View file

@ -115,11 +115,11 @@ object FormFieldDirectives extends FormFieldDirectives {
import akka.http.scaladsl.server.util.TupleOps._
import akka.http.scaladsl.server.util.BinaryPolyFunc
implicit def forTuple[T](implicit fold: FoldLeft[Directive0, T, ConvertParamDefAndConcatenate.type]): FieldDefAux[T, fold.Out] =
implicit def forTuple[T](implicit fold: FoldLeft[Directive0, T, ConvertFieldDefAndConcatenate.type]): FieldDefAux[T, fold.Out] =
fieldDef[T, fold.Out](fold(pass, _))
object ConvertParamDefAndConcatenate extends BinaryPolyFunc {
implicit def from[P, TA, TB](implicit fdef: FieldDefAux[P, Directive[TB]], ev: Join[TA, TB]) =
object ConvertFieldDefAndConcatenate extends BinaryPolyFunc {
implicit def from[P, TA, TB](implicit fdef: FieldDefAux[P, Directive[TB]], ev: Join[TA, TB]): BinaryPolyFunc.Case[Directive[TA], P, ConvertFieldDefAndConcatenate.type] { type Out = Directive[ev.Out] } =
at[Directive[TA], P] { (a, t) a & fdef(t) }
}
}

View file

@ -137,7 +137,7 @@ object ParameterDirectives extends ParameterDirectives {
paramDef[T, fold.Out](fold(BasicDirectives.pass, _))
object ConvertParamDefAndConcatenate extends BinaryPolyFunc {
implicit def from[P, TA, TB](implicit pdef: ParamDef[P] { type Out = Directive[TB] }, ev: Join[TA, TB]) =
implicit def from[P, TA, TB](implicit pdef: ParamDef[P] { type Out = Directive[TB] }, ev: Join[TA, TB]): BinaryPolyFunc.Case[Directive[TA], P, ConvertParamDefAndConcatenate.type] { type Out = Directive[ev.Out] } =
at[Directive[TA], P] { (a, t) a & pdef(t) }
}
}

View file

@ -42,20 +42,22 @@ object TupleOps {
type Out
def apply(prefix: P, suffix: S): Out
}
type JoinAux[P, S, O] = Join[P, S] { type Out = O }
object Join extends LowLevelJoinImplicits {
// O(1) shortcut for the Join[Unit, T] case to avoid O(n) runtime in this case
implicit def join0P[T] =
implicit def join0P[T]: JoinAux[Unit, T, T] =
new Join[Unit, T] {
type Out = T
def apply(prefix: Unit, suffix: T): Out = suffix
}
// we implement the join by folding over the suffix with the prefix as growing accumulator
object Fold extends BinaryPolyFunc {
implicit def step[T, A](implicit append: AppendOne[T, A]) = at[T, A](append(_, _))
implicit def step[T, A](implicit append: AppendOne[T, A]): BinaryPolyFunc.Case[T, A, Fold.type] { type Out = append.Out } =
at[T, A](append(_, _))
}
}
sealed abstract class LowLevelJoinImplicits {
implicit def join[P, S](implicit fold: FoldLeft[P, S, Join.Fold.type]) =
implicit def join[P, S](implicit fold: FoldLeft[P, S, Join.Fold.type]): JoinAux[P, S, fold.Out] =
new Join[P, S] {
type Out = fold.Out
def apply(prefix: P, suffix: S): Out = fold(prefix, suffix)