From f662fdda8e7aa365c2e5ead13cadf24473577d6f Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 18 Oct 2017 19:10:42 -0500 Subject: [PATCH] Rewrite to function syntax --- .../src/main/scala/sbt/internal/util/AList.scala | 8 ++++---- .../src/main/scala/sbt/internal/util/INode.scala | 2 +- .../src/main/scala/sbt/internal/util/PMap.scala | 5 ++--- .../src/main/scala/sbt/internal/util/Settings.scala | 6 +++--- main-settings/src/main/scala/sbt/Structure.scala | 2 +- tasks-standard/src/main/scala/sbt/std/System.scala | 2 +- tasks-standard/src/main/scala/sbt/std/TaskExtra.scala | 4 ++-- tasks-standard/src/test/scala/Test.scala | 4 ++-- 8 files changed, 16 insertions(+), 17 deletions(-) diff --git a/internal/util-collection/src/main/scala/sbt/internal/util/AList.scala b/internal/util-collection/src/main/scala/sbt/internal/util/AList.scala index 7685f9c5f..cc5343d2f 100644 --- a/internal/util-collection/src/main/scala/sbt/internal/util/AList.scala +++ b/internal/util-collection/src/main/scala/sbt/internal/util/AList.scala @@ -27,7 +27,7 @@ trait AList[K[L[x]]] { } object AList { - type Empty = AList[({ type l[L[x]] = Unit })#l] + type Empty = AList[ConstK[Unit]#l] /** AList for Unit, which represents a sequence that is always empty.*/ val empty: Empty = new Empty { @@ -37,7 +37,7 @@ object AList { def traverse[M[_], N[_], P[_]](in: Unit, f: M ~> (N ∙ P)#l)(implicit np: Applicative[N]): N[Unit] = np.pure(()) } - type SeqList[T] = AList[({ type l[L[x]] = List[L[T]] })#l] + type SeqList[T] = AList[λ[L[x] => List[L[T]]]] /** AList for a homogeneous sequence. */ def seq[T]: SeqList[T] = new SeqList[T] { @@ -67,7 +67,7 @@ object AList { override def toList[M[_]](k: KL[M]) = k.toList } - type Single[A] = AList[({ type l[L[x]] = L[A] })#l] + type Single[A] = AList[λ[L[x] => L[A]]] /** AList for a single value. */ def single[A]: Single[A] = new Single[A] { @@ -76,7 +76,7 @@ object AList { def traverse[M[_], N[_], P[_]](a: M[A], f: M ~> (N ∙ P)#l)(implicit np: Applicative[N]): N[P[A]] = f(a) } - type ASplit[K[L[x]], B[x]] = AList[({ type l[L[x]] = K[(L ∙ B)#l] })#l] + type ASplit[K[L[x]], B[x]] = AList[λ[L[x] => K[(L ∙ B)#l]]] /** AList that operates on the outer type constructor `A` of a composition `[x] A[B[x]]` for type constructors `A` and `B`*/ def asplit[K[L[x]], B[x]](base: AList[K]): ASplit[K, B] = new ASplit[K, B] { diff --git a/internal/util-collection/src/main/scala/sbt/internal/util/INode.scala b/internal/util-collection/src/main/scala/sbt/internal/util/INode.scala index 90e004efa..ca7cf5f3d 100644 --- a/internal/util-collection/src/main/scala/sbt/internal/util/INode.scala +++ b/internal/util-collection/src/main/scala/sbt/internal/util/INode.scala @@ -204,7 +204,7 @@ abstract class EvaluateSettings[Scope] { new MixedNode[ConstK[Unit]#l, T]((), _ => f(), AList.empty) private[this] def single[S, T](in: INode[S], f: S => T): INode[T] = - new MixedNode[({ type l[L[x]] = L[S] })#l, T](in, f, AList.single[S]) + new MixedNode[λ[L[x] => L[S]], T](in, f, AList.single[S]) private[this] final class BindNode[S, T](in: INode[S], f: S => INode[T]) extends INode[T] { protected def dependsOn = in :: Nil diff --git a/internal/util-collection/src/main/scala/sbt/internal/util/PMap.scala b/internal/util-collection/src/main/scala/sbt/internal/util/PMap.scala index a488fb32f..3d8cf19fd 100644 --- a/internal/util-collection/src/main/scala/sbt/internal/util/PMap.scala +++ b/internal/util-collection/src/main/scala/sbt/internal/util/PMap.scala @@ -31,8 +31,7 @@ trait IMap[K[_], V[_]] extends (K ~> V) with RMap[K, V] { def remove[T](k: K[T]): IMap[K, V] def mapValue[T](k: K[T], init: V[T], f: V[T] => V[T]): IMap[K, V] def mapValues[V2[_]](f: V ~> V2): IMap[K, V2] - def mapSeparate[VL[_], VR[_]](f: V ~> ({ type l[T] = Either[VL[T], VR[T]] })#l) - : (IMap[K, VL], IMap[K, VR]) + def mapSeparate[VL[_], VR[_]](f: V ~> λ[T => Either[VL[T], VR[T]]]): (IMap[K, VL], IMap[K, VR]) } trait PMap[K[_], V[_]] extends (K ~> V) with RMap[K, V] { @@ -69,7 +68,7 @@ object IMap { def mapValues[V2[_]](f: V ~> V2) = new IMap0[K, V2](backing.mapValues(x => f(x))) - def mapSeparate[VL[_], VR[_]](f: V ~> ({ type l[T] = Either[VL[T], VR[T]] })#l) = { + def mapSeparate[VL[_], VR[_]](f: V ~> λ[T => Either[VL[T], VR[T]]]) = { val mapped = backing.iterator.map { case (k, v) => f(v) match { diff --git a/internal/util-collection/src/main/scala/sbt/internal/util/Settings.scala b/internal/util-collection/src/main/scala/sbt/internal/util/Settings.scala index 6ff3c98e6..a99bf0a33 100644 --- a/internal/util-collection/src/main/scala/sbt/internal/util/Settings.scala +++ b/internal/util-collection/src/main/scala/sbt/internal/util/Settings.scala @@ -101,14 +101,14 @@ trait Init[Scope] { def bind[S, T](in: Initialize[S])(f: S => Initialize[T]): Initialize[T] = new Bind(f, in) def map[S, T](in: Initialize[S])(f: S => T): Initialize[T] = - new Apply[({ type l[L[x]] = L[S] })#l, T](f, in, AList.single[S]) + new Apply[λ[L[x] => L[S]], T](f, in, AList.single[S]) def app[K[L[x]], T](inputs: K[Initialize])(f: K[Id] => T)( implicit alist: AList[K] ): Initialize[T] = new Apply[K, T](f, inputs, alist) def uniform[S, T](inputs: Seq[Initialize[S]])(f: Seq[S] => T): Initialize[T] = - new Apply[({ type l[L[x]] = List[L[S]] })#l, T](f, inputs.toList, AList.seq[S]) + new Apply[λ[L[x] => List[L[S]]], T](f, inputs.toList, AList.seq[S]) /** * The result of this initialization is the validated `key`. @@ -560,7 +560,7 @@ trait Init[Scope] { def zip[S](o: Initialize[S]): Initialize[(T, S)] = zipTupled(o)(idFun) def zipWith[S, U](o: Initialize[S])(f: (T, S) => U): Initialize[U] = zipTupled(o)(f.tupled) private[this] def zipTupled[S, U](o: Initialize[S])(f: ((T, S)) => U): Initialize[U] = - new Apply[({ type l[L[x]] = (L[T], L[S]) })#l, U](f, (this, o), AList.tuple2[T, S]) + new Apply[λ[L[x] => (L[T], L[S])], U](f, (this, o), AList.tuple2[T, S]) /** A fold on the static attributes of this and nested Initializes. */ private[sbt] def processAttributes[S](init: S)(f: (S, AttributeMap) => S): S diff --git a/main-settings/src/main/scala/sbt/Structure.scala b/main-settings/src/main/scala/sbt/Structure.scala index 54a421cfe..9b1427e04 100644 --- a/main-settings/src/main/scala/sbt/Structure.scala +++ b/main-settings/src/main/scala/sbt/Structure.scala @@ -441,7 +441,7 @@ object Scoped { ) private[this] def onTasks[T](f: K[Task] => Task[T]): App[T] = - Def.app[({ type l[L[x]] = K[(L ∙ Task)#l] })#l, Task[T]](inputs)(f)(AList.asplit[K, Task](a)) + Def.app[λ[L[x] => K[(L ∙ Task)#l]], Task[T]](inputs)(f)(AList.asplit[K, Task](a)) def flatMap[T](f: Fun[Id, Task[T]]): App[T] = onTasks(_.flatMap(convert(f))) def flatMapR[T](f: Fun[Result, Task[T]]): App[T] = onTasks(_.flatMapR(convert(f))) diff --git a/tasks-standard/src/main/scala/sbt/std/System.scala b/tasks-standard/src/main/scala/sbt/std/System.scala index 5beb6cd66..2f5b65861 100644 --- a/tasks-standard/src/main/scala/sbt/std/System.scala +++ b/tasks-standard/src/main/scala/sbt/std/System.scala @@ -58,7 +58,7 @@ object Transform { } def uniform[T, D](tasks: Seq[Task[D]])(f: Seq[Result[D]] => Either[Task[T], T]): Node[Task, T] = - toNode[T, ({ type l[L[x]] = List[L[D]] })#l](tasks.toList)(f)(AList.seq[D]) + toNode[T, λ[L[x] => List[L[D]]]](tasks.toList)(f)(AList.seq[D]) def toNode[T, k[L[x]]](inputs: k[Task])(f: k[Result] => Either[Task[T], T])( implicit a: AList[k]): Node[Task, T] = new Node[Task, T] { diff --git a/tasks-standard/src/main/scala/sbt/std/TaskExtra.scala b/tasks-standard/src/main/scala/sbt/std/TaskExtra.scala index 5d7bd1b96..b94ea5e1c 100644 --- a/tasks-standard/src/main/scala/sbt/std/TaskExtra.scala +++ b/tasks-standard/src/main/scala/sbt/std/TaskExtra.scala @@ -118,7 +118,7 @@ trait TaskExtra { } final implicit def multT2Task[A, B](in: (Task[A], Task[B])) = - multInputTask[({ type l[L[x]] = (L[A], L[B]) })#l](in)(AList.tuple2[A, B]) + multInputTask[λ[L[x] => (L[A], L[B])]](in)(AList.tuple2[A, B]) final implicit def multInputTask[K[L[X]]](tasks: K[Task])(implicit a: AList[K]): MultiInTask[K] = new MultiInTask[K] { @@ -248,7 +248,7 @@ object TaskExtra extends TaskExtra { } def reducePair[S](a: Task[S], b: Task[S], f: (S, S) => S): Task[S] = - multInputTask[({ type l[L[x]] = (L[S], L[S]) })#l]((a, b))(AList.tuple2[S, S]) map f.tupled + multInputTask[λ[L[x] => (L[S], L[S])]]((a, b))(AList.tuple2[S, S]) map f.tupled def anyFailM[K[L[x]]](implicit a: AList[K]): K[Result] => Seq[Incomplete] = in => { val incs = failuresM(a)(in) diff --git a/tasks-standard/src/test/scala/Test.scala b/tasks-standard/src/test/scala/Test.scala index 07a6c11b6..0574118ca 100644 --- a/tasks-standard/src/test/scala/Test.scala +++ b/tasks-standard/src/test/scala/Test.scala @@ -11,9 +11,9 @@ import sbt.internal.util.AList object Test extends std.TaskExtra { def t2[A, B](a: Task[A], b: Task[B]) = - multInputTask[({ type l[L[x]] = (L[A], L[B]) })#l]((a, b))(AList.tuple2) + multInputTask[λ[L[x] => (L[A], L[B])]]((a, b))(AList.tuple2) def t3[A, B, C](a: Task[A], b: Task[B], c: Task[C]) = - multInputTask[({ type l[L[x]] = (L[A], L[B], L[C]) })#l]((a, b, c))(AList.tuple3) + multInputTask[λ[L[x] => (L[A], L[B], L[C])]]((a, b, c))(AList.tuple3) val a = task(3) val b = task[Boolean](sys.error("test"))