mirror of https://github.com/sbt/sbt.git
add Types.idFun to replace Predef.identity, replace a :== overload
idFun[T]: T => T instead of identity[T](t: T): T doesn't require a new class file when used as a function value replaced overloads of :== that assigned the Scoped reference on the right to the Scoped on the left with <<= scoped.identity
This commit is contained in:
parent
fee9429b03
commit
818382766e
|
|
@ -8,6 +8,7 @@ package sbt
|
|||
import Load.BuildStructure
|
||||
import complete.{DefaultParsers, Parser}
|
||||
import DefaultParsers._
|
||||
import Types.idFun
|
||||
import java.net.URI
|
||||
|
||||
object Act
|
||||
|
|
@ -55,7 +56,7 @@ object Act
|
|||
val allKeys = (Set.empty[String] /: confMap.values)(_ ++ _)
|
||||
token(ID examples allKeys).flatMap { keyString =>
|
||||
val conf = confMap.flatMap { case (key, value) => if(value contains keyString) key :: Nil else Nil } headOption;
|
||||
getKey(keyMap, keyString, k => (k, conf.flatMap(identity)))
|
||||
getKey(keyMap, keyString, k => (k, conf flatMap idFun))
|
||||
}
|
||||
}
|
||||
def getKey[T](keyMap: Map[String,AttributeKey[_]], keyString: String, f: AttributeKey[_] => T): Parser[T] =
|
||||
|
|
|
|||
|
|
@ -126,11 +126,11 @@ object Defaults
|
|||
definedSbtPlugins <<= discoverPlugins,
|
||||
inTask(run)(runnerSetting :: Nil).head,
|
||||
selectMainClass <<= discoveredMainClasses map selectRunMain,
|
||||
mainClass in run :== selectMainClass in run,
|
||||
mainClass in run <<= (selectMainClass in run).identity,
|
||||
mainClass <<= discoveredMainClasses map selectPackageMain,
|
||||
run <<= runTask(fullClasspath, mainClass in run, runner in run),
|
||||
runMain <<= runMainTask(fullClasspath, runner in run),
|
||||
scaladocOptions :== scalacOptions,
|
||||
scaladocOptions <<= scalacOptions.identity,
|
||||
doc <<= docTask,
|
||||
copyResources <<= copyResourcesTask
|
||||
)
|
||||
|
|
@ -486,14 +486,14 @@ object Classpaths
|
|||
val baseSettings: Seq[Setting[_]] = Seq(
|
||||
unmanagedBase <<= baseDirectory / "lib",
|
||||
normalizedName <<= name(StringUtilities.normalize),
|
||||
organization :== normalizedName,
|
||||
organization <<= normalizedName.identity,
|
||||
classpathFilter in GlobalScope :== "*.jar",
|
||||
fullResolvers <<= (projectResolver,resolvers,sbtPlugin,sbtResolver) map { (pr,rs,isPlugin,sr) =>
|
||||
val base = pr +: Resolver.withDefaultResolvers(rs)
|
||||
if(isPlugin) sr +: base else base
|
||||
},
|
||||
offline in GlobalScope :== false,
|
||||
moduleID :== normalizedName,
|
||||
moduleID <<= normalizedName.identity,
|
||||
defaultConfiguration in GlobalScope :== Some(Configurations.Compile),
|
||||
defaultConfigurationMapping in GlobalScope <<= defaultConfiguration{ case Some(d) => "*->" + d.name; case None => "*->*" },
|
||||
ivyPaths <<= (baseDirectory, appConfiguration) { (base, app) => new IvyPaths(base, Option(app.provider.scalaProvider.launcher.ivyHome).map(_ / "cache")) },
|
||||
|
|
@ -512,7 +512,7 @@ object Classpaths
|
|||
moduleConfigurations in GlobalScope :== Nil,
|
||||
publishTo in GlobalScope :== None,
|
||||
artifactPath in makePom <<= artifactPathSetting(artifact in makePom),
|
||||
publishArtifact in makePom :== publishMavenStyle,
|
||||
publishArtifact in makePom <<= publishMavenStyle.identity,
|
||||
artifact in makePom <<= moduleID( name => Artifact(name, "pom", "pom") ),
|
||||
projectID <<= (organization,moduleID,version,artifacts){ (org,module,version,as) =>
|
||||
ModuleID(org, module, version).cross(true).artifacts(as : _*)
|
||||
|
|
@ -531,7 +531,7 @@ object Classpaths
|
|||
moduleSettings <<= moduleSettings0,
|
||||
makePomConfiguration <<= (artifactPath in makePom)(file => makePomConfigurationTask(file)),
|
||||
deliverLocalConfiguration <<= (crossTarget, ivyLoggingLevel) map { (outDir, level) => deliverConfig( outDir, logging = level ) },
|
||||
deliverConfiguration :== deliverLocalConfiguration,
|
||||
deliverConfiguration <<= deliverLocalConfiguration.identity,
|
||||
publishConfiguration <<= (packagedArtifacts, publishTo, publishMavenStyle, deliver, ivyLoggingLevel) map { (arts, publishTo, mavenStyle, ivyFile, level) =>
|
||||
publishConfig(arts, if(mavenStyle) None else Some(ivyFile), resolverName = getPublishTo(publishTo).name, logging = level)
|
||||
},
|
||||
|
|
@ -738,7 +738,7 @@ object Classpaths
|
|||
( key in (dep, ConfigKey(conf)) ) get data getOrElse const(Nil)
|
||||
def defaultConfigurationTask(p: ResolvedReference, data: Settings[Scope]): Configuration =
|
||||
flatten(defaultConfiguration in p get data) getOrElse Configurations.Default
|
||||
def flatten[T](o: Option[Option[T]]): Option[T] = o flatMap identity
|
||||
def flatten[T](o: Option[Option[T]]): Option[T] = o flatMap idFun
|
||||
|
||||
lazy val dbResolver = Resolver.url("sbt-db", new URL("http://databinder.net/repo/"))(Resolver.ivyStylePatterns)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ package sbt
|
|||
import complete.{DefaultParsers, HistoryCommands, Parser}
|
||||
import HistoryCommands.{Start => HistoryPrefix}
|
||||
import compiler.EvalImports
|
||||
|
||||
import Types.idFun
|
||||
|
||||
import Command.applyEffect
|
||||
import Keys.{analysis,historyPath,logged,shellPrompt}
|
||||
|
|
@ -64,7 +64,7 @@ object BuiltinCommands
|
|||
def DefaultBootCommands: Seq[String] = LoadProject :: (IfLast + " " + Shell) :: Nil
|
||||
|
||||
def nop = Command.custom(s => success(() => s))
|
||||
def ignore = Command.command(FailureWall)(identity)
|
||||
def ignore = Command.command(FailureWall)(idFun)
|
||||
|
||||
def detail(selected: Iterable[String])(h: Help): Option[String] =
|
||||
h.detail match { case (commands, value) => if( selected exists commands ) Some(value) else None }
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ package sbt
|
|||
import Keys.{appConfiguration, stateBuildStructure, commands, configuration, historyPath, logged, projectCommand, sessionSettings, shellPrompt, streams, thisProject, thisProjectRef, watch}
|
||||
import Scope.{GlobalScope,ThisScope}
|
||||
import CommandSupport.logger
|
||||
import Types.idFun
|
||||
|
||||
sealed trait ProjectDefinition[PR <: ProjectReference]
|
||||
{
|
||||
|
|
@ -125,7 +126,7 @@ object Project extends Init[Scope] with ProjectExtra
|
|||
def commandsIn(axis: ResolvedReference) = commands in axis get structure.data toList ;
|
||||
|
||||
val allCommands = commandsIn(ref) ++ commandsIn(BuildRef(ref.build)) ++ (commands in Global get structure.data toList )
|
||||
val history = get(historyPath) flatMap identity
|
||||
val history = get(historyPath) flatMap idFun
|
||||
val prompt = get(shellPrompt)
|
||||
val watched = get(watch)
|
||||
val commandDefs = allCommands.distinct.flatten[Command].map(_ tag (projectCommand, true))
|
||||
|
|
|
|||
|
|
@ -140,12 +140,12 @@ object Scoped
|
|||
protected final val scoped = ScopedKey(scope, key)
|
||||
|
||||
final def :==(value: S): Setting[S] = :=(value)
|
||||
final def :==(value: ScopedSetting[S]): Setting[S] = <<=(value(identity))
|
||||
final def := (value: => S): Setting[S] = setting(scoped, Project.value(value))
|
||||
final def ~= (f: S => S): Setting[S] = Project.update(scoped)(f)
|
||||
final def <<= (app: Initialize[S]): Setting[S] = setting(scoped, app)
|
||||
|
||||
final def apply[T](f: S => T): Initialize[T] = Apply.single(scoped)(f)
|
||||
def identity: Initialize[S] = apply(idFun)
|
||||
|
||||
final def get(settings: Settings[Scope]): Option[S] = settings.get(scope, key)
|
||||
}
|
||||
|
|
@ -161,7 +161,6 @@ object Scoped
|
|||
def :==(value: S): ScS = :=(value)
|
||||
def ::=(value: Task[S]): ScS = Project.setting(scoped, Project.value( value ))
|
||||
def := (value: => S): ScS = ::=(mktask(value))
|
||||
def :== (v: ScopedTask[S]): ScS = Project.setting(scoped, Project.app(ScopedKey(v.scope, v.key) :^: KNil)(_.head) )
|
||||
def :== (v: ScopedSetting[S]): ScS = <<=( v(const))
|
||||
def ~= (f: S => S): ScS = Project.update(scoped)( _ map f )
|
||||
|
||||
|
|
@ -182,6 +181,7 @@ object Scoped
|
|||
def mapFailure[T](f: Incomplete => T): App[T] = mapR(f compose failM)
|
||||
def andFinally(fin: => Unit): App[S] = mk(_ andFinally fin)
|
||||
def doFinally(t: Task[Unit]): App[S] = mk(_ doFinally t)
|
||||
def identity: App[S] = mk(idFun)
|
||||
|
||||
def || [T >: S](alt: Task[T]): App[T] = mk(_ || alt)
|
||||
def && [T](alt: Task[T]): App[T] = mk(_ && alt)
|
||||
|
|
@ -199,7 +199,7 @@ object Scoped
|
|||
implicit def richSettingSeq[T](in: Seq[ScopedSetting[T]]): RichSettingSeq[T] = new RichSettingSeq(in)
|
||||
final class RichSettingSeq[T](keys: Seq[ScopedSetting[T]])
|
||||
{
|
||||
def join: Initialize[Seq[T]] = joinWith(identity)
|
||||
def join: Initialize[Seq[T]] = joinWith(idFun)
|
||||
def joinWith[S](f: Seq[T] => S): Initialize[S] = Apply.uniform(keys)(f)
|
||||
}
|
||||
implicit def richTaskSeq[T](in: Seq[ScopedTask[T]]): RichTaskSeq[T] = new RichTaskSeq(in)
|
||||
|
|
@ -317,7 +317,7 @@ object Scoped
|
|||
protected def convertH[Ret](f: Fun[Id,Ret]): In => Ret
|
||||
protected def convertK[M[_],Ret](f: Fun[M,Ret]): KList[M,In] => Ret
|
||||
private[this] val red = reduced(keys)
|
||||
|
||||
|
||||
def flatMap[T](f: Fun[Id,Task[T]]): App[T] = red.combine(Combine.flatMapR, convertH(f) compose allM)
|
||||
def flatMapR[T](f: Fun[Result,Task[T]]): App[T] = red.combine(Combine.flatMapR, convertK(f))
|
||||
def map[T](f: Fun[Id, T]): App[T] = red.combine[Id,T](Combine.mapR, convertH(f) compose allM)
|
||||
|
|
@ -328,48 +328,56 @@ object Scoped
|
|||
final class RichTaskable2[A,B](t2: (ScopedTaskable[A], ScopedTaskable[B])) extends RichTaskables(t2._1 :^: t2._2 :^: KNil)
|
||||
{
|
||||
type Fun[M[_],Ret] = (M[A],M[B]) => Ret
|
||||
def identity = map( (a,b) => (a,b) )
|
||||
protected def convertH[R](f: (A,B) => R) = { case a :+: b :+: HNil => f(a,b) }
|
||||
protected def convertK[M[_],R](f: (M[A],M[B]) => R) = { case a :^: b :^: KNil => f(a,b) }
|
||||
}
|
||||
final class RichTaskable3[A,B,C](t3: (ScopedTaskable[A], ScopedTaskable[B], ScopedTaskable[C])) extends RichTaskables(t3._1 :^: t3._2 :^: t3._3 :^: KNil)
|
||||
{
|
||||
type Fun[M[_],Ret] = (M[A],M[B],M[C]) => Ret
|
||||
def identity = map( (a,b,c) => (a,b,c) )
|
||||
protected def convertH[R](f: Fun[Id,R]) = { case a :+: b :+: c :+: HNil => f(a,b,c) }
|
||||
protected def convertK[M[_],R](f: Fun[M,R]) = { case a :^: b :^: c :^: KNil => f(a,b,c) }
|
||||
}
|
||||
final class RichTaskable4[A,B,C,D](t4: (ScopedTaskable[A], ScopedTaskable[B], ScopedTaskable[C], ScopedTaskable[D])) extends RichTaskables(t4._1 :^: t4._2 :^: t4._3 :^: t4._4 :^: KNil)
|
||||
{
|
||||
type Fun[M[_],Ret] = (M[A],M[B],M[C],M[D]) => Ret
|
||||
def identity = map( (a,b,c,d) => (a,b,c,d) )
|
||||
protected def convertH[R](f: Fun[Id,R]) = { case a :+: b :+: c :+: d :+: HNil => f(a,b,c,d) }
|
||||
protected def convertK[M[_],R](f: Fun[M,R]) = { case a :^: b :^: c :^: d :^: KNil => f(a,b,c,d) }
|
||||
}
|
||||
final class RichTaskable5[A,B,C,D,E](t5: (ScopedTaskable[A], ScopedTaskable[B], ScopedTaskable[C], ScopedTaskable[D], ScopedTaskable[E])) extends RichTaskables(t5._1 :^: t5._2 :^: t5._3 :^: t5._4 :^: t5._5 :^: KNil)
|
||||
{
|
||||
type Fun[M[_],Ret] = (M[A],M[B],M[C],M[D],M[E]) => Ret
|
||||
def identity = map( (a,b,c,d,e) => (a,b,c,d,e) )
|
||||
protected def convertH[R](f: Fun[Id,R]) = { case a :+: b :+: c :+: d :+: e :+: HNil => f(a,b,c,d,e) }
|
||||
protected def convertK[M[_],R](f: Fun[M,R]) = { case a :^: b :^: c :^: d :^: e :^: KNil => f(a,b,c,d,e) }
|
||||
}
|
||||
final class RichTaskable6[A,B,C,D,E,F](t6: (ScopedTaskable[A], ScopedTaskable[B], ScopedTaskable[C], ScopedTaskable[D], ScopedTaskable[E], ScopedTaskable[F])) extends RichTaskables(t6._1 :^: t6._2 :^: t6._3 :^: t6._4 :^: t6._5 :^: t6._6 :^: KNil)
|
||||
{
|
||||
type Fun[M[_],Ret] = (M[A],M[B],M[C],M[D],M[E],M[F]) => Ret
|
||||
def identity = map( (a,b,c,d,e,f) => (a,b,c,d,e,f) )
|
||||
protected def convertH[R](z: Fun[Id,R]) = { case a :+: b :+: c :+: d :+: e :+: f :+: HNil => z(a,b,c,d,e,f) }
|
||||
protected def convertK[M[_],R](z: Fun[M,R]) = { case a :^: b :^: c :^: d :^: e :^: f :^: KNil => z(a,b,c,d,e,f) }
|
||||
}
|
||||
final class RichTaskable7[A,B,C,D,E,F,G](t7: (ScopedTaskable[A], ScopedTaskable[B], ScopedTaskable[C], ScopedTaskable[D], ScopedTaskable[E], ScopedTaskable[F], ScopedTaskable[G])) extends RichTaskables(t7._1 :^: t7._2 :^: t7._3 :^: t7._4 :^: t7._5 :^: t7._6 :^: t7._7 :^: KNil)
|
||||
{
|
||||
type Fun[M[_],Ret] = (M[A],M[B],M[C],M[D],M[E],M[F],M[G]) => Ret
|
||||
def identity = map( (a,b,c,d,e,f,g) => (a,b,c,d,e,f,g) )
|
||||
protected def convertH[R](z: Fun[Id,R]) = { case a :+: b :+: c :+: d :+: e :+: f :+: g :+: HNil => z(a,b,c,d,e,f,g) }
|
||||
protected def convertK[M[_],R](z: Fun[M,R]) = { case a :^: b :^: c :^: d :^: e :^: f :^: g :^: KNil => z(a,b,c,d,e,f,g) }
|
||||
}
|
||||
final class RichTaskable8[A,B,C,D,E,F,G,H](t8: (ScopedTaskable[A], ScopedTaskable[B], ScopedTaskable[C], ScopedTaskable[D], ScopedTaskable[E], ScopedTaskable[F], ScopedTaskable[G], ScopedTaskable[H])) extends RichTaskables(t8._1 :^: t8._2 :^: t8._3 :^: t8._4 :^: t8._5 :^: t8._6 :^: t8._7 :^: t8._8 :^: KNil)
|
||||
{
|
||||
type Fun[M[_],Ret] = (M[A],M[B],M[C],M[D],M[E],M[F],M[G],M[H]) => Ret
|
||||
def identity = map( (a,b,c,d,e,f,g,h) => (a,b,c,d,e,f,g,h) )
|
||||
protected def convertH[R](z: Fun[Id,R]) = { case a :+: b :+: c :+: d :+: e :+: f :+: g :+: h :+: HNil => z(a,b,c,d,e,f,g,h) }
|
||||
protected def convertK[M[_],R](z: Fun[M,R]) = { case a :^: b :^: c :^: d :^: e :^: f :^: g :^: h :^: KNil => z(a,b,c,d,e,f,g,h) }
|
||||
}
|
||||
final class RichTaskable9[A,B,C,D,E,F,G,H,I](t9: (ScopedTaskable[A], ScopedTaskable[B], ScopedTaskable[C], ScopedTaskable[D], ScopedTaskable[E], ScopedTaskable[F], ScopedTaskable[G], ScopedTaskable[H], ScopedTaskable[I])) extends RichTaskables(t9._1 :^: t9._2 :^: t9._3 :^: t9._4 :^: t9._5 :^: t9._6 :^: t9._7 :^: t9._8 :^: t9._9 :^: KNil)
|
||||
{
|
||||
type Fun[M[_],Ret] = (M[A],M[B],M[C],M[D],M[E],M[F],M[G],M[H],M[I]) => Ret
|
||||
def identity = map( (a,b,c,d,e,f,g,h,i) => (a,b,c,d,e,f,g,h,i) )
|
||||
protected def convertH[R](z: Fun[Id,R]) = { case a :+: b :+: c :+: d :+: e :+: f :+: g :+: h :+: i :+: HNil => z(a,b,c,d,e,f,g,h,i) }
|
||||
protected def convertK[M[_],R](z: Fun[M,R]) = { case a :^: b :^: c :^: d :^: e :^: f :^: g :^: h :^: i :^: KNil => z(a,b,c,d,e,f,g,h,i) }
|
||||
}
|
||||
|
|
@ -381,6 +389,7 @@ object Scoped
|
|||
type App[T] = Initialize[Task[T]]
|
||||
private[this] val red = reduced(keys)
|
||||
|
||||
def identity: App[In] = map(idFun)
|
||||
def flatMap[T](f: In => Task[T]): App[T] = flatMapR(f compose allM)
|
||||
def flatMapR[T](f: Results[In] => Task[T]): App[T] = red.combine(Combine.flatMapR, f)
|
||||
def map[T](f: In => T): App[T] = mapR(f compose allM)
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ trait TaskExtra
|
|||
final implicit def toTasks[S](in: Seq[() => S]): Seq[Task[S]] = in.map(toTask)
|
||||
final implicit def iterableTask[S](in: Seq[S]): ForkTask[S, Seq] = new ForkTask[S, Seq] {
|
||||
def fork[T](f: S => T): Seq[Task[T]] = in.map(x => task(f(x)))
|
||||
def tasks: Seq[Task[S]] = fork(identity)
|
||||
def tasks: Seq[Task[S]] = fork(idFun)
|
||||
}
|
||||
|
||||
final implicit def joinAnyTasks(in: Seq[Task[_]]): JoinTask[Any, Seq] = joinTasks[Any](in map (x => x: Task[Any]))
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ trait TypeFunctions
|
|||
final val left = new (Id ~> P1of2[Left, Nothing]#Flip) { def apply[T](t: T) = Left(t) }
|
||||
final val right = new (Id ~> P1of2[Right, Nothing]#Apply) { def apply[T](t: T) = Right(t) }
|
||||
final val some = new (Id ~> Some) { def apply[T](t: T) = Some(t) }
|
||||
final def idFun[T] = (t: T) => t
|
||||
|
||||
def nestCon[M[_], N[_], G[_]](f: M ~> N): (M ∙ G)#l ~> (N ∙ G)#l =
|
||||
f.asInstanceOf[(M ∙ G)#l ~> (N ∙ G)#l] // implemented with a cast to avoid extra object+method call. castless version:
|
||||
|
|
|
|||
Loading…
Reference in New Issue