diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-05 07:35:56 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-05 07:35:56 -0800 |
commit | 3ebb8788b8fb3d09dedb7ac11956d780dfadb34b (patch) | |
tree | 770ab4b4125034d03384d5cf082b89ed86993dac /core | |
parent | 9e1ba56eb49fb62d20fc4ede0627194304a854e8 (diff) | |
download | mill-3ebb8788b8fb3d09dedb7ac11956d780dfadb34b.tar.gz mill-3ebb8788b8fb3d09dedb7ac11956d780dfadb34b.tar.bz2 mill-3ebb8788b8fb3d09dedb7ac11956d780dfadb34b.zip |
Rename `ApplicativeMacros` and contents to shorter names
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/scala/forge/define/Applicative.scala (renamed from core/src/main/scala/forge/define/ApplicativeMacros.scala) | 28 | ||||
-rw-r--r-- | core/src/main/scala/forge/define/Target.scala | 14 | ||||
-rw-r--r-- | core/src/test/scala/forge/ApplicativeMacrosTests.scala | 36 |
3 files changed, 59 insertions, 19 deletions
diff --git a/core/src/main/scala/forge/define/ApplicativeMacros.scala b/core/src/main/scala/forge/define/Applicative.scala index 1461d009..ba71221e 100644 --- a/core/src/main/scala/forge/define/ApplicativeMacros.scala +++ b/core/src/main/scala/forge/define/Applicative.scala @@ -2,20 +2,30 @@ package forge.define import forge.util.Args +import scala.annotation.compileTimeOnly import scala.collection.mutable import scala.reflect.macros.blackbox.Context -object ApplicativeMacros { - trait Zippable[T[_]]{ +object Applicative { + trait Applyable[T]{ + @compileTimeOnly("Target#apply() can only be used with a T{...} block") + def apply(): T = ??? + } + trait Applyer[T[_]]{ def map[A, B](a: T[A], f: A => B): T[B] def zipMap[R]()(f: () => R) = map(zip(), (_: Unit) => f()) def zipMap[A, R](a: T[A])(f: A => R) = map(a, f) def zipMap[A, B, R](a: T[A], b: T[B])(f: (A, B) => R) = map(zip(a, b), f.tupled) - def zipMap[A, B, C, R](a: T[A], b: T[B], c: T[C])(f: (A, B, C) => R) = map(zip(a, b, c), f.tupled) - def zipMap[A, B, C, D, R](a: T[A], b: T[B], c: T[C], d: T[D])(f: (A, B, C, D) => R) = map(zip(a, b, c, d), f.tupled) - def zipMap[A, B, C, D, E, R](a: T[A], b: T[B], c: T[C], d: T[D], e: T[E])(f: (A, B, C, D, E) => R) = map(zip(a, b, c, d, e), f.tupled) - def zipMap[A, B, C, D, E, F, R](a: T[A], b: T[B], c: T[C], d: T[D], e: T[E], f: T[F])(cb: (A, B, C, D, E, F) => R) = map(zip(a, b, c, d, e, f), cb.tupled) - def zipMap[A, B, C, D, E, F, G, R](a: T[A], b: T[B], c: T[C], d: T[D], e: T[E], f: T[F], g: T[G])(cb: (A, B, C, D, E, F, G) => R) = map(zip(a, b, c, d, e, f, g), cb.tupled) + def zipMap[A, B, C, R](a: T[A], b: T[B], c: T[C]) + (f: (A, B, C) => R) = map(zip(a, b, c), f.tupled) + def zipMap[A, B, C, D, R](a: T[A], b: T[B], c: T[C], d: T[D]) + (f: (A, B, C, D) => R) = map(zip(a, b, c, d), f.tupled) + def zipMap[A, B, C, D, E, R](a: T[A], b: T[B], c: T[C], d: T[D], e: T[E]) + (f: (A, B, C, D, E) => R) = map(zip(a, b, c, d, e), f.tupled) + def zipMap[A, B, C, D, E, F, R](a: T[A], b: T[B], c: T[C], d: T[D], e: T[E], f: T[F]) + (cb: (A, B, C, D, E, F) => R) = map(zip(a, b, c, d, e, f), cb.tupled) + def zipMap[A, B, C, D, E, F, G, R](a: T[A], b: T[B], c: T[C], d: T[D], e: T[E], f: T[F], g: T[G]) + (cb: (A, B, C, D, E, F, G) => R) = map(zip(a, b, c, d, e, f, g), cb.tupled) def zip(): T[Unit] def zip[A](a: T[A]): T[Tuple1[A]] def zip[A, B](a: T[A], b: T[B]): T[(A, B)] @@ -41,7 +51,7 @@ object ApplicativeMacros { def rec(t: Tree): Iterator[c.Tree] = Iterator(t) ++ t.children.flatMap(rec(_)) val bound = collection.mutable.Buffer.empty[(c.Tree, Symbol)] - val targetApplySym = tt.tpe.member(TermName("apply")) + val targetApplySym = typeOf[Applyable[_]].member(TermName("apply")) // Derived from @olafurpg's // https://gist.github.com/olafurpg/596d62f87bf3360a29488b725fbc7608 @@ -87,7 +97,7 @@ object ApplicativeMacros { val owner = c.internal.enclosingOwner val ownerIsCacherClass = owner.owner.isClass && - owner.owner.asClass.baseClasses.exists(_.fullName == "forge.define.ApplicativeMacros.Cacher") + owner.owner.asClass.baseClasses.exists(_.fullName == "forge.define.Applicative.Cacher") if (ownerIsCacherClass && !owner.isMethod){ c.abort( diff --git a/core/src/main/scala/forge/define/Target.scala b/core/src/main/scala/forge/define/Target.scala index 591fd68e..0aafee89 100644 --- a/core/src/main/scala/forge/define/Target.scala +++ b/core/src/main/scala/forge/define/Target.scala @@ -1,6 +1,7 @@ package forge.define import ammonite.ops.{CommandResult, mkdir} +import forge.define.Applicative.Applyable import forge.eval.PathRef import forge.util.{Args, JsonFormatters} import play.api.libs.json.{Format, Json} @@ -10,7 +11,7 @@ import scala.collection.mutable import scala.language.experimental.macros import scala.reflect.macros.blackbox.Context -abstract class Target[T] extends Target.Ops[T]{ +abstract class Target[T] extends Target.Ops[T] with Applyable[T]{ /** * What other Targets does this Target depend on? */ @@ -26,21 +27,18 @@ abstract class Target[T] extends Target.Ops[T]{ * anyway? */ def sideHash: Int = 0 - - @compileTimeOnly("Target#apply() can only be used with a T{...} block") - def apply(): T = ??? } -object Target extends ApplicativeMacros.Zippable[Target]{ +object Target extends Applicative.Applyer[Target]{ - type Cacher = ApplicativeMacros.Cacher[Target[_]] + type Cacher = Applicative.Cacher[Target[_]] class Target0[T](t: T) extends Target[T]{ lazy val t0 = t val inputs = Nil def evaluate(args: Args) = t0 } - def apply[T](t: Target[T]): Target[T] = macro ApplicativeMacros.impl0[Target, T] - def apply[T](t: T): Target[T] = macro ApplicativeMacros.impl[Target, T] + def apply[T](t: Target[T]): Target[T] = macro Applicative.impl0[Target, T] + def apply[T](t: T): Target[T] = macro Applicative.impl[Target, T] abstract class Ops[T]{ this: Target[T] => def map[V](f: T => V) = new Target.Mapped(this, f) diff --git a/core/src/test/scala/forge/ApplicativeMacrosTests.scala b/core/src/test/scala/forge/ApplicativeMacrosTests.scala index 24851283..daeaa9b4 100644 --- a/core/src/test/scala/forge/ApplicativeMacrosTests.scala +++ b/core/src/test/scala/forge/ApplicativeMacrosTests.scala @@ -1,9 +1,41 @@ package forge +import forge.define.{Applicative, Target} import utest._ -object ApplicativeMacrosTests extends TestSuite{ +import language.experimental.macros + +object ApplicativeMacrosTests extends TestSuite /*with define.Applicative.Applyer[Option]*/ { + +// def apply[T](t: Option[T]): Option[T] = macro Applicative.impl0[Option, T] +// def apply[T](t: T): Option[T] = macro Applicative.impl[Option, T] +// +// type O[+T] = Option[T] +// def map[A, B](a: O[A], f: A => B) = a.map(f) +// def zip() = Some(()) +// def zip[A](a: O[A]) = a.map(Tuple1(_)) +// def zip[A, B](a: O[A], b: O[B]) = { +// for(a <- a; b <- b) yield (a, b) +// } +// def zip[A, B, C](a: O[A], b: O[B], c: O[C]) = { +// for(a <- a; b <- b; c <- c) yield (a, b, c) +// } +// def zip[A, B, C, D](a: O[A], b: O[B], c: O[C], d: O[D]) = { +// for(a <- a; b <- b; c <- c; d <- d) yield (a, b, c, d) +// } +// def zip[A, B, C, D, E](a: O[A], b: O[B], c: O[C], d: O[D], e: O[E]) = { +// for(a <- a; b <- b; c <- c; d <- d; e <- e) yield (a, b, c, d, e) +// } +// def zip[A, B, C, D, E, F](a: O[A], b: O[B], c: O[C], d: O[D], e: O[E], f: O[F]) ={ +// for(a <- a; b <- b; c <- c; d <- d; e <- e; f <- f) yield (a, b, c, d, e, f) +// } +// def zip[A, B, C, D, E, F, G](a: O[A], b: O[B], c: O[C], d: O[D], e: O[E], f: O[F], g: O[G]) = { +// for(a <- a; b <- b; c <- c; d <- d; e <- e; f <- f; g <- g) yield (a, b, c, d, e, f, g) +// } val tests = Tests{ 'hello - { - 'hello +// assert( +// apply("lol " + 1) == Some("lol 1"), +// apply("lol " + None()) == None +// ) } } } |