mirror of https://github.com/sbt/sbt.git
Merge pull request #7491 from adpi2/misc-cleanup
[2.x] Miscellaneous cleanup
This commit is contained in:
commit
64be877549
|
|
@ -92,7 +92,9 @@ trait Cont:
|
|||
given qctx.type = qctx
|
||||
Expr
|
||||
.summon[Applicative[F]]
|
||||
.getOrElse(sys.error(s"Applicative[F] not found for ${TypeRepr.of[F].typeSymbol}"))
|
||||
.getOrElse(
|
||||
report.errorAndAbort(s"Applicative[F] not found for ${TypeRepr.of[F].typeSymbol}")
|
||||
)
|
||||
|
||||
def summonHashWriter[A: Type]: Expr[HashWriter[A]] =
|
||||
import conv.qctx
|
||||
|
|
|
|||
|
|
@ -377,6 +377,7 @@ trait ParserMain {
|
|||
|
||||
implicit def literalRichCharParser(c: Char): RichParser[Char] = richParser(c)
|
||||
implicit def literalRichStringParser(s: String): RichParser[String] = richParser(s)
|
||||
extension (s: String) def *(n: Int): String = augmentString(s).*(n)
|
||||
|
||||
/**
|
||||
* Construct a parser that is valid, but has no valid result. This is used as a way to provide a
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@
|
|||
package sbt.internal.util
|
||||
package complete
|
||||
|
||||
import scala.collection.StringOps
|
||||
|
||||
object JLineTest {
|
||||
import DefaultParsers._
|
||||
|
||||
|
|
@ -155,12 +153,12 @@ object ParserExample {
|
|||
val an = repeat(a, min = n, max = n)
|
||||
val ann = aqn ~ an
|
||||
|
||||
def r = apply(ann)(new StringOps("a") * (n * 2)).resultEmpty
|
||||
def r = apply(ann)("a" * (n * 2)).resultEmpty
|
||||
println(r.isValid)
|
||||
}
|
||||
def run2(n: Int): Unit = {
|
||||
val ab = "ab".?.*
|
||||
val r = apply(ab)(new StringOps("a") * n).resultEmpty
|
||||
val r = apply(ab)("a" * n).resultEmpty
|
||||
println(r)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ package sbt
|
|||
|
||||
import java.io.File
|
||||
import java.util.regex.{ Pattern, PatternSyntaxException }
|
||||
import scala.collection.immutable.StringOps
|
||||
|
||||
import sbt.internal.util.AttributeKey
|
||||
import sbt.internal.util.complete.Parser
|
||||
|
|
@ -43,7 +42,7 @@ object CommandUtil {
|
|||
for ((a, b) <- in) yield pre + fill(a, width) + sep + b
|
||||
}
|
||||
|
||||
def fill(s: String, size: Int): String = s + StringOps(" ") * math.max(size - s.length, 0)
|
||||
def fill(s: String, size: Int): String = s + " " * math.max(size - s.length, 0)
|
||||
|
||||
def withAttribute[T](s: State, key: AttributeKey[T], ifMissing: String)(f: T => State): State =
|
||||
s get key match {
|
||||
|
|
|
|||
|
|
@ -13,13 +13,12 @@ import sbt.internal.util.complete.Parser
|
|||
|
||||
object MultiParserSpec {
|
||||
val parser: Parser[Seq[String]] = BasicCommands.multiParserImpl(None)
|
||||
implicit class StringOps(val s: String) {
|
||||
extension (s: String)
|
||||
def parse: Seq[String] = Parser.parse(s, parser) match {
|
||||
case Right(x) => x
|
||||
case Left(x) => sys.error(s)
|
||||
}
|
||||
def parseEither: Either[String, Seq[String]] = Parser.parse(s, parser)
|
||||
}
|
||||
}
|
||||
import sbt.MultiParserSpec._
|
||||
class MultiParserSpec extends AnyFlatSpec {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ package sbt
|
|||
import sbt.internal.util.complete.Parser
|
||||
import Def.{ Initialize, ScopedKey }
|
||||
import std.TaskExtra._
|
||||
import sbt.internal.util.{ ~>, AttributeKey, Types }
|
||||
import sbt.internal.util.{ AttributeKey, Types }
|
||||
import sbt.internal.util.Types._
|
||||
import sbt.internal.util.Util._
|
||||
import sbt.util.Applicative
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ package sbt
|
|||
import scala.annotation.targetName
|
||||
|
||||
import sbt.internal.util.Types.*
|
||||
import sbt.internal.util.{ ~>, AttributeKey, Settings, SourcePosition }
|
||||
import sbt.internal.util.{ AttributeKey, Settings, SourcePosition }
|
||||
import sbt.internal.util.TupleMapExtension.*
|
||||
import sbt.util.OptJsonWriter
|
||||
import sbt.ConcurrentRestrictions.Tag
|
||||
|
|
@ -92,15 +92,12 @@ sealed abstract class SettingKey[A1]
|
|||
final inline def ++=[A2](inline vs: A2)(using Append.Values[A1, A2]): Setting[A1] =
|
||||
appendN(settingMacro[A2](vs))
|
||||
|
||||
final def appendN[V](vs: Initialize[V])(using
|
||||
ev: Append.Values[A1, V]
|
||||
): Setting[A1] = make(vs)(ev.appendValues)
|
||||
final def appendN[V](vs: Initialize[V])(using ev: Append.Values[A1, V]): Setting[A1] =
|
||||
make(vs)(ev.appendValues)
|
||||
|
||||
final inline def <+=[A2](inline v: Initialize[A2]): Setting[A1] =
|
||||
${ TaskMacro.fakeSettingAppend1Position[A1, A2]('v) }
|
||||
final inline def <+=[A2](v: Initialize[A2]): Setting[A1] = ${ TaskMacro.fakeAppend1Impl }
|
||||
|
||||
final inline def <++=[A2](inline vs: Initialize[A2]): Setting[A1] =
|
||||
${ TaskMacro.fakeSettingAppendNPosition[A1, A2]('vs) }
|
||||
final inline def <++=[A2](vs: Initialize[A2]): Setting[A1] = ${ TaskMacro.fakeAppendNImpl }
|
||||
|
||||
final inline def -=[A2](inline v: A2)(using Remove.Value[A1, A2]): Setting[A1] =
|
||||
remove1(settingMacro[A2](v))
|
||||
|
|
@ -172,11 +169,11 @@ sealed abstract class TaskKey[A1]
|
|||
ev: Append.Values[A1, A2]
|
||||
): Setting[Task[A1]] = make(vs)(ev.appendValues)
|
||||
|
||||
inline def <+=[A2](inline v: Initialize[Task[A2]]): Setting[Task[A1]] =
|
||||
${ TaskMacro.fakeTaskAppend1Position[A1, A2]('v) }
|
||||
inline def <+=[A2](v: Initialize[Task[A2]]): Setting[Task[A1]] =
|
||||
${ TaskMacro.fakeAppend1Impl }
|
||||
|
||||
inline def <++=[A2](inline vs: Initialize[Task[A2]]): Setting[Task[A1]] =
|
||||
${ TaskMacro.fakeTaskAppendNPosition[A1, A2]('vs) }
|
||||
inline def <++=[A2](vs: Initialize[Task[A2]]): Setting[Task[A1]] =
|
||||
${ TaskMacro.fakeAppendNImpl }
|
||||
|
||||
final inline def -=[A2](v: A2)(using Remove.Value[A1, A2]): Setting[Task[A1]] =
|
||||
remove1[A2](taskMacro[A2](v))
|
||||
|
|
@ -334,8 +331,7 @@ object Scoped:
|
|||
private[sbt] final inline def :==(inline app: A1): Setting[A1] =
|
||||
set(Def.valueStrict(app))
|
||||
|
||||
inline def <<=(inline app: Initialize[A1]): Setting[A1] =
|
||||
${ TaskMacro.fakeSettingAssignImpl('app) }
|
||||
inline def <<=(app: Initialize[A1]): Setting[A1] = ${ TaskMacro.fakeAssignImpl }
|
||||
|
||||
/** In addition to creating Def.setting(...), this captures the source position. */
|
||||
inline def set(inline app: Initialize[A1]): Setting[A1] =
|
||||
|
|
@ -479,8 +475,7 @@ object Scoped:
|
|||
inline def :=(inline a: A1): Setting[Task[A1]] =
|
||||
set(taskMacro(a))
|
||||
|
||||
inline def <<=(inline app: Initialize[Task[A1]]): Setting[Task[A1]] =
|
||||
${ TaskMacro.fakeItaskAssignPosition[A1]('app) }
|
||||
inline def <<=(app: Initialize[Task[A1]]): Setting[Task[A1]] = ${ TaskMacro.fakeAssignImpl }
|
||||
|
||||
/** In addition to creating Def.setting(...), this captures the source position. */
|
||||
inline def set(inline app: Initialize[Task[A1]]): Setting[Task[A1]] =
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import sbt.internal.util.appmacro.{ Convert, ContextUtil }
|
|||
import sbt.internal.util.complete.Parser
|
||||
import Def.Initialize
|
||||
import sbt.util.Applicative
|
||||
import sbt.internal.util.Types.Compose
|
||||
import scala.quoted.*
|
||||
|
||||
class InputInitConvert[C <: Quotes & scala.Singleton](override val qctx: C, valStart: Int)
|
||||
|
|
@ -95,7 +94,7 @@ class FullConvert[C <: Quotes & scala.Singleton](override val qctx: C, valStart:
|
|||
}
|
||||
Converted.success(t.asTerm)
|
||||
|
||||
def appExpr: Expr[Applicative[Compose[Initialize, Task]]] =
|
||||
def appExpr: Expr[Applicative[[a] =>> Initialize[Task[a]]]] =
|
||||
'{ FullInstance.initializeTaskMonad }
|
||||
end FullConvert
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ package std
|
|||
|
||||
import Def.Initialize
|
||||
import sbt.util.{ Applicative, Monad }
|
||||
import sbt.internal.util.Types.{ const, Compose }
|
||||
import sbt.internal.util.Types.const
|
||||
import sbt.internal.util.complete.{ DefaultParsers, Parser }
|
||||
|
||||
object InitializeInstance:
|
||||
|
|
@ -28,8 +28,8 @@ end InitializeInstance
|
|||
private[std] object ComposeInstance:
|
||||
import InitializeInstance.initializeMonad
|
||||
val InitInstance = summon[Applicative[Initialize]]
|
||||
val F1F2: Applicative[Compose[Initialize, Task]] =
|
||||
summon[Applicative[Compose[Initialize, Task]]]
|
||||
val F1F2: Applicative[[a] =>> Initialize[Task[a]]] =
|
||||
summon[Applicative[[a] =>> Initialize[Task[a]]]]
|
||||
end ComposeInstance
|
||||
|
||||
object ParserInstance:
|
||||
|
|
@ -60,8 +60,8 @@ object FullInstance:
|
|||
)
|
||||
|
||||
given Monad[Initialize] = InitializeInstance.initializeMonad
|
||||
val F1F2: Applicative[Compose[Initialize, Task]] = ComposeInstance.F1F2
|
||||
given initializeTaskMonad: Monad[Compose[Initialize, Task]] with
|
||||
val F1F2: Applicative[[a] =>> Initialize[Task[a]]] = ComposeInstance.F1F2
|
||||
given initializeTaskMonad: Monad[[a] =>> Initialize[Task[a]]] with
|
||||
type F[x] = Initialize[Task[x]]
|
||||
override def pure[A1](x: () => A1): Initialize[Task[A1]] = F1F2.pure(x)
|
||||
override def ap[A1, A2](ff: Initialize[Task[A1 => A2]])(
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import sbt.internal.util.appmacro.{
|
|||
// MonadInstance
|
||||
}
|
||||
// import Instance.Transform
|
||||
import sbt.internal.util.{ LinePosition, NoPosition, SourcePosition, ~> }
|
||||
import sbt.internal.util.{ LinePosition, NoPosition, SourcePosition }
|
||||
|
||||
import language.experimental.macros
|
||||
import scala.annotation.tailrec
|
||||
|
|
@ -43,7 +43,7 @@ object TaskMacro:
|
|||
final val appendNMigration =
|
||||
"`<++=` operator is removed. Try `lhs ++= { x.value }`\n or see https://www.scala-sbt.org/1.x/docs/Migrating-from-sbt-013x.html."
|
||||
final val assignMigration =
|
||||
"""`<<=` operator is removed. Use `key := { x.value }` or `key ~= (old => { newValue })`.
|
||||
"""`<<=` operator is removed. Use `key := { x.value }` or `key ~= {old => newValue }`.
|
||||
|See https://www.scala-sbt.org/1.x/docs/Migrating-from-sbt-013x.html""".stripMargin
|
||||
|
||||
type F[x] = Initialize[Task[x]]
|
||||
|
|
@ -113,49 +113,17 @@ object TaskMacro:
|
|||
// Error macros (Restligeist)
|
||||
// These macros are there just so we can fail old operators like `<<=` and provide useful migration information.
|
||||
|
||||
def fakeSettingAssignImpl[A1: Type](app: Expr[Initialize[A1]])(using
|
||||
qctx: Quotes
|
||||
): Expr[Setting[A1]] =
|
||||
import qctx.reflect.*
|
||||
report.errorAndAbort(TaskMacro.assignMigration)
|
||||
def errorAndAbort(message: String)(using quotes: Quotes): Nothing =
|
||||
quotes.reflect.report.errorAndAbort(message)
|
||||
|
||||
def fakeSettingAppend1Position[A1: Type, A2: Type](
|
||||
@deprecated("unused", "") v: Expr[Initialize[A2]]
|
||||
)(using
|
||||
qctx: Quotes
|
||||
): Expr[Setting[A1]] =
|
||||
import qctx.reflect.*
|
||||
report.errorAndAbort(TaskMacro.append1Migration)
|
||||
def fakeAssignImpl(using qctx: Quotes): Nothing =
|
||||
qctx.reflect.report.errorAndAbort(assignMigration)
|
||||
|
||||
def fakeSettingAppendNPosition[A1: Type, A2: Type](
|
||||
@deprecated("unused", "") vs: Expr[Initialize[A2]]
|
||||
)(using
|
||||
qctx: Quotes
|
||||
): Expr[Setting[A1]] =
|
||||
import qctx.reflect.*
|
||||
report.errorAndAbort(TaskMacro.appendNMigration)
|
||||
def fakeAppend1Impl(using qctx: Quotes): Nothing =
|
||||
qctx.reflect.report.errorAndAbort(append1Migration)
|
||||
|
||||
def fakeItaskAssignPosition[A1: Type](
|
||||
@deprecated("unused", "") app: Expr[Initialize[Task[A1]]]
|
||||
)(using qctx: Quotes): Expr[Setting[Task[A1]]] =
|
||||
import qctx.reflect.*
|
||||
report.errorAndAbort(TaskMacro.assignMigration)
|
||||
|
||||
def fakeTaskAppend1Position[A1: Type, A2: Type](
|
||||
@deprecated("unused", "") v: Expr[Initialize[Task[A2]]]
|
||||
)(using
|
||||
qctx: Quotes
|
||||
): Expr[Setting[Task[A1]]] =
|
||||
import qctx.reflect.*
|
||||
report.errorAndAbort(TaskMacro.append1Migration)
|
||||
|
||||
def fakeTaskAppendNPosition[A1: Type, A2: Type](
|
||||
@deprecated("unused", "") vs: Expr[Initialize[Task[A2]]]
|
||||
)(using
|
||||
qctx: Quotes
|
||||
): Expr[Setting[Task[A1]]] =
|
||||
import qctx.reflect.*
|
||||
report.errorAndAbort(TaskMacro.appendNMigration)
|
||||
def fakeAppendNImpl(using qctx: Quotes): Nothing =
|
||||
qctx.reflect.report.errorAndAbort(appendNMigration)
|
||||
|
||||
// Implementations of <<= macro variations for tasks and settings.
|
||||
// These just get the source position of the call site.
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ import sbt.internal.{
|
|||
SettingCompletions,
|
||||
SessionSettings
|
||||
}
|
||||
import sbt.internal.util.{ AttributeKey, AttributeMap, Dag, Relation, Settings, ~> }
|
||||
import sbt.internal.util.Types.const // , idFun }
|
||||
import sbt.internal.util.{ AttributeKey, AttributeMap, Dag, Relation, Settings }
|
||||
import sbt.internal.util.Types.const
|
||||
import sbt.internal.util.complete.DefaultParsers
|
||||
import sbt.internal.server.ServerHandler
|
||||
import sbt.librarymanagement.Configuration
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import sbt.internal.inc.{ MappedFileConverter, ScalaInstance, ZincLmUtil, ZincUt
|
|||
import sbt.internal.server.BuildServerEvalReporter
|
||||
import sbt.internal.util.Attributed.data
|
||||
import sbt.internal.util.Types.const
|
||||
import sbt.internal.util.{ Attributed, Settings, ~> }
|
||||
import sbt.internal.util.{ Attributed, Settings }
|
||||
import sbt.io.{ GlobFilter, IO, Path }
|
||||
import sbt.librarymanagement.ivy.{ InlineIvyConfiguration, IvyDependencyResolution, IvyPaths }
|
||||
import sbt.librarymanagement.{ Configuration, Configurations, Resolver }
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import sbt.util.{ Level, Logger }
|
|||
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.mutable
|
||||
import scala.collection.immutable.StringOps
|
||||
import scala.concurrent.duration._
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
|
|
@ -506,9 +505,7 @@ object Watch {
|
|||
val opts = distinctOptions(options).sortBy(_.input)
|
||||
val alignmentLength = opts.map(_.display.length).max + 1
|
||||
val formatted =
|
||||
opts.map(o =>
|
||||
s"${o.display}${StringOps(" ") * (alignmentLength - o.display.length)}: ${o.description}"
|
||||
)
|
||||
opts.map(o => s"${o.display}${" " * (alignmentLength - o.display.length)}: ${o.description}")
|
||||
s"Options:\n${formatted.mkString(" ", "\n ", "")}"
|
||||
}
|
||||
private def distinctOptions(options: Seq[InputOption]): Seq[InputOption] = {
|
||||
|
|
@ -539,7 +536,7 @@ object Watch {
|
|||
{
|
||||
val countStr = s"$count. "
|
||||
Some(s"$countStr${waitMessage(project, commands)
|
||||
.mkString(s"\n${StringOps(" ") * countStr.length}")}")
|
||||
.mkString(s"\n${" " * countStr.length}")}")
|
||||
}
|
||||
}.label("Watched.defaultStartWatch")
|
||||
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ trait Import {
|
|||
type UnprintableException = sbt.internal.util.UnprintableException
|
||||
val Util = sbt.internal.util.Util
|
||||
// val ~> = sbt.internal.util.~>
|
||||
type ~>[-K[_], +V[_]] = sbt.internal.util.~>[K, V]
|
||||
// type ~>[-K[_], +V[_]] = sbt.internal.util.~>[K, V]
|
||||
|
||||
// sbt.internal.util.complete
|
||||
object complete {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ package sbt
|
|||
|
||||
import sbt.internal.Action
|
||||
import sbt.internal.util.Types.const
|
||||
import sbt.internal.util.{ ~>, AttributeKey, AttributeMap }
|
||||
import sbt.internal.util.{ AttributeKey, AttributeMap }
|
||||
import ConcurrentRestrictions.{ Tag, TagMap, tagsKey }
|
||||
import sbt.util.Monad
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ package sbt
|
|||
package std
|
||||
|
||||
import sbt.internal.Action
|
||||
import sbt.internal.util.{ ~>, DelegatingPMap, RMap }
|
||||
import sbt.internal.util.{ DelegatingPMap, RMap }
|
||||
import sbt.internal.util.TupleMapExtension.*
|
||||
import TaskExtra.{ all, existToAny }
|
||||
import sbt.internal.util.Types.*
|
||||
|
|
@ -20,9 +20,6 @@ object Transform:
|
|||
|
||||
def fromDummyStrict[T](original: Task[T], value: T): Task[T] = fromDummy(original)(value)
|
||||
|
||||
implicit def to_~>|[K[_], V[_]](map: RMap[K, V]): ~>|[K, V] =
|
||||
[A] => (k: K[A]) => map.get(k)
|
||||
|
||||
final case class DummyTaskMap(mappings: List[TaskAndValue[_]]) {
|
||||
def ::[T](tav: (Task[T], T)): DummyTaskMap =
|
||||
DummyTaskMap(new TaskAndValue(tav._1, tav._2) :: mappings)
|
||||
|
|
@ -30,17 +27,17 @@ object Transform:
|
|||
|
||||
final class TaskAndValue[T](val task: Task[T], val value: T)
|
||||
|
||||
def dummyMap(dummyMap: DummyTaskMap): TaskId ~>| Task = {
|
||||
def dummyMap(dummyMap: DummyTaskMap): [A] => TaskId[A] => Option[Task[A]] = {
|
||||
val pmap = new DelegatingPMap[TaskId, Task](new collection.mutable.ListMap)
|
||||
def add[T](dummy: TaskAndValue[T]): Unit = {
|
||||
pmap(dummy.task) = fromDummyStrict(dummy.task, dummy.value)
|
||||
}
|
||||
dummyMap.mappings.foreach(x => add(x))
|
||||
pmap
|
||||
([A] => (task: TaskId[A]) => pmap.get(task))
|
||||
}
|
||||
|
||||
/** Applies `map`, returning the result if defined or returning the input unchanged otherwise. */
|
||||
implicit def getOrId(map: TaskId ~>| Task): [A] => TaskId[A] => Task[A] =
|
||||
private def getOrId(map: [A] => TaskId[A] => Option[Task[A]]): [A] => TaskId[A] => Task[A] =
|
||||
[A] => (in: TaskId[A]) => map(in).getOrElse(in.asInstanceOf)
|
||||
|
||||
def apply(dummies: DummyTaskMap) = taskToNode(getOrId(dummyMap(dummies)))
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ package sbt
|
|||
import java.util.concurrent.ExecutionException
|
||||
|
||||
import sbt.internal.util.ErrorHandling.wideConvert
|
||||
import sbt.internal.util.{ DelegatingPMap, IDSet, PMap, RMap, ~> }
|
||||
import sbt.internal.util.{ DelegatingPMap, IDSet, PMap, RMap }
|
||||
import sbt.internal.util.Types.const
|
||||
import sbt.internal.util.Util.nilSeq
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
package sbt
|
||||
|
||||
import sbt.internal.util.~>
|
||||
|
||||
// used instead of Either[Incomplete, T] for type inference
|
||||
|
||||
/** Result of completely evaluating a task. */
|
||||
|
|
|
|||
|
|
@ -26,15 +26,14 @@ trait RMap[K[_], V[_]] {
|
|||
sealed case class TPair[T](key: K[T], value: V[T])
|
||||
}
|
||||
|
||||
trait IMap[K[_], V[_]] extends (K ~> V) with RMap[K, V] {
|
||||
trait IMap[K[_], V[_]] extends RMap[K, V] {
|
||||
def put[T](k: K[T], v: V[T]): IMap[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: [A] => V[A] => V2[A]): IMap[K, V2]
|
||||
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] {
|
||||
trait PMap[K[_], V[_]] extends RMap[K, V] {
|
||||
def update[T](k: K[T], v: V[T]): Unit
|
||||
def remove[T](k: K[T]): Option[V[T]]
|
||||
def getOrUpdate[T](k: K[T], make: => V[T]): V[T]
|
||||
|
|
@ -80,21 +79,6 @@ object IMap {
|
|||
k -> f(v.asInstanceOf[V[Any]])
|
||||
}.toArray: _*))
|
||||
|
||||
def mapSeparate[VL[_], VR[_]](f: V ~> λ[T => Either[VL[T], VR[T]]]) = {
|
||||
val left = new java.util.concurrent.ConcurrentHashMap[K[Any], VL[Any]]
|
||||
val right = new java.util.concurrent.ConcurrentHashMap[K[Any], VR[Any]]
|
||||
Par(backing.toVector).foreach { case (k, v) =>
|
||||
f(v.asInstanceOf[V[Any]]) match {
|
||||
case Left(l) => left.put(k, l)
|
||||
case Right(r) => right.put(k, r)
|
||||
}
|
||||
}
|
||||
(
|
||||
new IMap0[K, VL](new WrappedMap(left.asInstanceOf)),
|
||||
new IMap0[K, VR](new WrappedMap(right.asInstanceOf))
|
||||
)
|
||||
}
|
||||
|
||||
def toSeq = backing.toSeq.asInstanceOf[Seq[(K[Any], V[Any])]]
|
||||
def keys = backing.keys.asInstanceOf[Iterable[K[Any]]]
|
||||
def values = backing.values.asInstanceOf[Iterable[V[Any]]]
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ trait Init[ScopeType]:
|
|||
* This can be useful when dealing with dynamic Initialize values.
|
||||
*/
|
||||
lazy val capturedTransformations: Initialize[[x] => Initialize[x] => Initialize[x]] =
|
||||
TransformCapture(idK[Initialize])
|
||||
TransformCapture([a] => (init: Initialize[a]) => init)
|
||||
|
||||
def setting[A1](
|
||||
key: ScopedKey[A1],
|
||||
|
|
|
|||
|
|
@ -11,84 +11,13 @@ trait TypeFunctions:
|
|||
type Id[X] = X
|
||||
type NothingK[X] = Nothing
|
||||
|
||||
/*
|
||||
import TypeFunctions._
|
||||
sealed trait Const[A] { type Apply[B] = A }
|
||||
sealed trait ConstK[A] { type l[L[x]] = A }
|
||||
type ConstK[A] = [F[_]] =>> A
|
||||
*/
|
||||
final val left: [A] => A => Left[A, Nothing] = [A] => (a: A) => Left(a)
|
||||
|
||||
type Compose[F1[_], F2[_]] = [a] =>> F1[F2[a]]
|
||||
|
||||
sealed trait ∙[A[_], B[_]] { type l[T] = A[B[T]] }
|
||||
private type AnyLeft[A] = Left[A, Nothing]
|
||||
private type AnyRight[A] = Right[Nothing, A]
|
||||
final val left: [A] => A => AnyLeft[A] = [A] => (a: A) => Left(a)
|
||||
|
||||
final val right: [A] => A => AnyRight[A] = [A] => (a: A) => Right(a)
|
||||
final val right: [A] => A => Right[Nothing, A] = [A] => (a: A) => Right(a)
|
||||
|
||||
final val some: [A] => A => Some[A] = [A] => (a: A) => Some(a)
|
||||
// Id ~> Left[*, Nothing] =
|
||||
// λ[Id ~> AnyLeft](Left(_)).setToString("TypeFunctions.left")
|
||||
// final val right: Id ~> Right[Nothing, *] =
|
||||
// λ[Id ~> AnyRight](Right(_)).setToString("TypeFunctions.right")
|
||||
// final val some: Id ~> Some[*] = λ[Id ~> Some](Some(_)).setToString("TypeFunctions.some")
|
||||
|
||||
final def idFun[A]: A => A = ((a: A) => a) // .setToString("TypeFunctions.id")
|
||||
final def const[A, B](b: B): A => B = ((_: A) => b) // .setToString(s"TypeFunctions.const($b)")
|
||||
|
||||
final def idK[F[_]]: [a] => F[a] => F[a] = [a] =>
|
||||
(fa: F[a]) => fa // .setToString("TypeFunctions.idK")
|
||||
|
||||
inline def nestCon[F1[_], F2[_], F3[_]](
|
||||
f: [a] => F1[a] => F2[a]
|
||||
): [a] => Compose[F1, F3][a] => Compose[F2, F3][a] =
|
||||
f.asInstanceOf[[a] => Compose[F1, F3][a] => Compose[F2, F3][a]]
|
||||
|
||||
/*
|
||||
type Endo[T] = T => T
|
||||
type ~>|[A[_], B[_]] = A ~> Compose[Option, B]#Apply
|
||||
*/
|
||||
type ~>|[F1[_], F2[_]] = [A] => F1[A] => Option[F2[A]]
|
||||
end TypeFunctions
|
||||
|
||||
/*
|
||||
object TypeFunctions extends TypeFunctions:
|
||||
|
||||
private implicit class Ops[T[_], R[_]](val underlying: T ~> R) extends AnyVal {
|
||||
def setToString(string: String): T ~> R = new (T ~> R) {
|
||||
override def apply[U](a: T[U]): R[U] = underlying(a)
|
||||
override def toString: String = string
|
||||
override def equals(o: Any): Boolean = underlying.equals(o)
|
||||
override def hashCode: Int = underlying.hashCode
|
||||
}
|
||||
}
|
||||
private implicit class FunctionOps[A, B](val f: A => B) extends AnyVal {
|
||||
def setToString(string: String): A => B = new (A => B) {
|
||||
override def apply(a: A): B = f(a)
|
||||
override def toString: String = string
|
||||
override def equals(o: Any): Boolean = f.equals(o)
|
||||
override def hashCode: Int = f.hashCode
|
||||
}
|
||||
}
|
||||
final def idFun[A]: A => A = ((a: A) => a)
|
||||
final def const[A, B](b: B): A => B = ((_: A) => b)
|
||||
|
||||
end TypeFunctions
|
||||
*/
|
||||
|
||||
trait ~>[-F1[_], +F2[_]] { outer =>
|
||||
def apply[A](f1: F1[A]): F2[A]
|
||||
// directly on ~> because of type inference limitations
|
||||
final def ∙[F3[_]](g: F3 ~> F1): F3 ~> F2 = new ~>[F3, F2] {
|
||||
override def apply[A](f3: F3[A]) = outer.apply(g(f3))
|
||||
}
|
||||
final def ∙[C, D](g: C => D)(implicit ev: D <:< F1[D]): C => F2[D] = i => apply(ev(g(i)))
|
||||
lazy val fn: [A] => F1[A] => F2[A] = [A] => (f1: F1[A]) => outer.apply[A](f1)
|
||||
}
|
||||
|
||||
/*
|
||||
object ~> {
|
||||
import TypeFunctions._
|
||||
val Id: Id ~> Id = idK[Id]
|
||||
implicit def tcIdEquals: Id ~> Id = Id
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
package sbt.util
|
||||
|
||||
import sbt.internal.util.Types.Compose
|
||||
|
||||
trait Applicative[F[_]] extends Apply[F]:
|
||||
def pure[A1](x: () => A1): F[A1]
|
||||
|
||||
|
|
@ -20,14 +18,12 @@ object Applicative:
|
|||
given Applicative[Option] = OptionInstances.optionMonad
|
||||
given Applicative[List] = ListInstances.listMonad
|
||||
|
||||
given [F1[_], F2[_]](using Applicative[F1], Applicative[F2]): Applicative[Compose[F1, F2]] with
|
||||
given [F1[_], F2[_]](using Applicative[F1], Applicative[F2]): Applicative[[a] =>> F1[F2[a]]] with
|
||||
type F[x] = F1[F2[x]]
|
||||
val F1 = summon[Applicative[F1]]
|
||||
val F2 = summon[Applicative[F2]]
|
||||
override def pure[A1](x: () => A1): F1[F2[A1]] = F1.pure(() => F2.pure(x))
|
||||
override def ap[A1, A2](f1f2f: Compose[F1, F2][A1 => A2])(
|
||||
f1f2a: Compose[F1, F2][A1]
|
||||
): F1[F2[A2]] =
|
||||
override def ap[A1, A2](f1f2f: F1[F2[A1 => A2]])(f1f2a: F1[F2[A1]]): F1[F2[A2]] =
|
||||
F1.ap(F1.map(f1f2f) { (f2f: F2[A1 => A2]) => (f2a: F2[A1]) => F2.ap(f2f)(f2a) })(f1f2a)
|
||||
|
||||
end Applicative
|
||||
|
|
|
|||
Loading…
Reference in New Issue