Permalink
Browse files

Some simplifications that were enabled by bug fixes in Scala 2.11

- Remove `ToShapedValue`
- Remove `otherOptionExtensionMethods`
  • Loading branch information...
1 parent ef65d0b commit 4468733506bee052449b43efd0f7c52619d15676 @szeiger szeiger committed Sep 30, 2015
@@ -15,8 +15,8 @@ class AggregateTest extends AsyncTest[RelationalTestDB] {
val ts = TableQuery[T]
def q1(i: Int) = for { t <- ts if t.a === i } yield t
def q2(i: Int) = (q1(i).length, q1(i).map(_.b).length, q1(i).map(_.b).countDefined, q1(i).map(_.a).sum, q1(i).map(_.b).sum, q1(i).map(_.b).avg)
- val q2_0 = q2(0).shaped
- val q2_1 = q2(1).shaped
+ val q2_0 = q2(0)
+ val q2_1 = q2(1)
ts.schema.create >>
(ts ++= Seq((1, Some(1)), (1, Some(3)), (1, None))) >>
q2_0.result.map(_ shouldBe (0, 0, 0, None, None, None)) >>
@@ -225,7 +225,7 @@ final class AnyOptionExtensionMethods[O <: Rep[_], P](val r: O) extends AnyVal {
def nonEmpty = isDefined
}
-trait ExtensionMethodConversions extends ExtensionMethodConversionsLowPriority {
+trait ExtensionMethodConversions {
implicit def columnExtensionMethods[B1 : BaseTypedType](c: Rep[B1]) = new BaseColumnExtensionMethods[B1](c)
implicit def optionColumnExtensionMethods[B1 : BaseTypedType](c: Rep[Option[B1]]) = new OptionColumnExtensionMethods[B1](c)
implicit def numericColumnExtensionMethods[B1](c: Rep[B1])(implicit tm: BaseTypedType[B1] with NumericTypedType) = new BaseNumericColumnExtensionMethods[B1](c)
@@ -242,14 +242,5 @@ trait ExtensionMethodConversions extends ExtensionMethodConversionsLowPriority {
implicit def singleColumnQueryExtensionMethods[B1 : BaseTypedType, C[_]](q: Query[Rep[B1], _, C]) = new SingleColumnQueryExtensionMethods[B1, B1, C](q)
implicit def singleOptionColumnQueryExtensionMethods[B1 : BaseTypedType, C[_]](q: Query[Rep[Option[B1]], _, C]) = new SingleColumnQueryExtensionMethods[B1, Option[B1], C](q)
- // Not possible on Scala 2.10 due to SI-3346
- //implicit def anyOptionExtensionMethods[T, P](v: Rep[Option[T]])(implicit ol: OptionLift[P, Rep[Option[T]]]) = new AnyOptionExtensionMethods[Rep[Option[T]], P](v)
-
- implicit def repOptionExtensionMethods[T <: Rep[_]](v: Rep[Option[T]]) = new AnyOptionExtensionMethods[Rep[Option[T]], T](v)
- implicit def baseColumnRepOptionExtensionMethods[T : TypedType](v: Rep[Option[T]]) = new AnyOptionExtensionMethods[Rep[Option[T]], Rep[T]](v)
- implicit def nestedOptionExtensionMethods[T](v: Rep[Option[Option[T]]]) = new AnyOptionExtensionMethods[Rep[Option[Option[T]]], Rep[Option[T]]](v)
-}
-
-trait ExtensionMethodConversionsLowPriority {
- implicit def otherOptionExtensionMethods[T](v: Rep[Option[T]]) = new AnyOptionExtensionMethods[Rep[Option[T]], T](v)
+ implicit def anyOptionExtensionMethods[T, P](v: Rep[Option[T]])(implicit ol: OptionLift[P, Rep[Option[T]]]) = new AnyOptionExtensionMethods[Rep[Option[T]], P](v)
}
@@ -270,18 +270,13 @@ case class ShapedValue[T, U](value: T, shape: Shape[_ <: FlatShapeLevel, T, U, _
def packedValue[R](implicit ev: Shape[_ <: FlatShapeLevel, T, _, R]): ShapedValue[R, U] = ShapedValue(shape.pack(value).asInstanceOf[R], shape.packedShape.asInstanceOf[Shape[FlatShapeLevel, R, U, _]])
def zip[T2, U2](s2: ShapedValue[T2, U2]) = new ShapedValue[(T, T2), (U, U2)]((value, s2.value), Shape.tuple2Shape(shape, s2.shape))
@inline def <>[R : ClassTag](f: (U => R), g: (R => Option[U])) = new MappedProjection[R, U](shape.toNode(value), MappedScalaType.Mapper(g.andThen(_.get).asInstanceOf[Any => Any], f.asInstanceOf[Any => Any], None), implicitly[ClassTag[R]])
+ @inline def shaped: ShapedValue[T, U] = this
}
object ShapedValue {
@inline implicit def shapedValueShape[T, U, Level <: ShapeLevel] = RepShape[Level, ShapedValue[T, U], U]
}
-// Work-around for SI-3346
-final class ToShapedValue[T](val value: T) extends AnyVal {
- @inline def shaped[U](implicit shape: Shape[_ <: FlatShapeLevel, T, U, _]) = new ShapedValue[T, U](value, shape)
- @inline def <>[R : ClassTag, U](f: (U => R), g: (R => Option[U]))(implicit shape: Shape[_ <: FlatShapeLevel, T, U, _]) = new MappedProjection[R, U](shape.toNode(value), MappedScalaType.Mapper(g.andThen(_.get).asInstanceOf[Any => Any], f.asInstanceOf[Any => Any], None), implicitly[ClassTag[R]])
-}
-
/** A limited version of ShapedValue which can be constructed for every type
* that has a valid shape. We use it to enforce that a table's * projection
* has a valid shape. A ProvenShape has itself a Shape so it can be used in
@@ -45,8 +45,8 @@ trait BasicProfile extends BasicActionComponent { driver: BasicDriver =>
implicit val slickDriver: driver.type = driver
- // Work-around for SI-3346
- @inline implicit final def anyToToShapedValue[T](value: T) = new ToShapedValue[T](value)
+ implicit final def anyToShapedValue[T, U](value: T)(implicit shape: Shape[_ <: FlatShapeLevel, T, U, _]): ShapedValue[T, U] =
+ new ShapedValue[T, U](value, shape)
implicit def repQueryActionExtensionMethods[U](rep: Rep[U]): QueryActionExtensionMethods[U, NoStream] =
createQueryActionExtensionMethods[U, NoStream](queryCompiler.run(rep.toNode).tree, ())
@@ -59,7 +59,6 @@ trait BasicProfile extends BasicActionComponent { driver: BasicDriver =>
// Applying a CompiledFunction always results in only a RunnableCompiled, not a StreamableCompiled, so we need this:
implicit def streamableAppliedCompiledFunctionActionExtensionMethods[R, RU, EU, C[_]](c: AppliedCompiledFunction[_, Query[R, EU, C], RU]): StreamingQueryActionExtensionMethods[RU, EU] =
createStreamingQueryActionExtensionMethods[RU, EU](c.compiledQuery, c.param)
- // This only works on Scala 2.11 due to SI-3346:
implicit def recordQueryActionExtensionMethods[M, R](q: M)(implicit shape: Shape[_ <: FlatShapeLevel, M, R, _]): QueryActionExtensionMethods[R, NoStream] =
createQueryActionExtensionMethods[R, NoStream](queryCompiler.run(shape.toNode(q)).tree, ())
}

0 comments on commit 4468733

Please sign in to comment.