avoid deprecated /: and :\

use foldLeft and foldRight

https://github.com/scala/scala/blob/v2.13.0/src/library/scala/collection/IterableOnce.scala#L682-L686
This commit is contained in:
xuwei-k 2019-08-30 11:20:53 +09:00
parent 4566ac3335
commit dfe789d7c6
28 changed files with 45 additions and 43 deletions

View File

@ -74,7 +74,7 @@ object KListBuilder extends TupleBuilder {
* The type constructor is tcVariable, so that it can be applied to [X] X or M later.
* When applied to `M`, this type gives the type of the `input` KList.
*/
val klistType: Type = (inputs :\ knilType)((in, klist) => kconsType(in.tpe, klist))
val klistType: Type = inputs.foldRight(knilType)((in, klist) => kconsType(in.tpe, klist))
val representationC = internal.polyType(tcVariable :: Nil, klistType)
val input = klist

View File

@ -48,7 +48,7 @@ object AList {
def seq[T]: SeqList[T] = new SeqList[T] {
def transform[M[_], N[_]](s: List[M[T]], f: M ~> N) = s.map(f.fn[T])
def foldr[M[_], A](s: List[M[T]], f: (M[_], A) => A, init: A): A =
(init /: s.reverse)((t, m) => f(m, t))
s.reverse.foldLeft(init)((t, m) => f(m, t))
override def apply[M[_], C](s: List[M[T]], f: List[T] => C)(
implicit ap: Applicative[M]

View File

@ -77,7 +77,7 @@ abstract class EvaluateSettings[ScopeType] {
}
private[this] def getResults(implicit delegates: ScopeType => Seq[ScopeType]) =
(empty /: static.toTypedSeq) {
static.toTypedSeq.foldLeft(empty) {
case (ss, static.TPair(key, node)) =>
if (key.key.isLocal) ss else ss.set(key.scope, key.key, node.get)
}

View File

@ -225,7 +225,7 @@ trait Init[ScopeType] {
}.toMap
def grouped(init: Seq[Setting[_]]): ScopedMap =
((IMap.empty: ScopedMap) /: init)((m, s) => add(m, s))
init.foldLeft(IMap.empty: ScopedMap)((m, s) => add(m, s))
def add[T](m: ScopedMap, s: Setting[T]): ScopedMap =
m.mapValue[T](s.key, Vector.empty[Setting[T]], ss => append(ss, s))
@ -399,7 +399,7 @@ trait Init[ScopeType] {
val empty = Map.empty[ScopedKey[_], Flattened]
val flattenedLocals = (empty /: ordered) { (cmap, c) =>
val flattenedLocals = ordered.foldLeft(empty) { (cmap, c) =>
cmap.updated(c.key, flatten(cmap, c.key, c.dependencies))
}
@ -859,7 +859,7 @@ trait Init[ScopeType] {
}
private[sbt] def processAttributes[S](init: S)(f: (S, AttributeMap) => S): S =
(init /: alist.toList(inputs)) { (v, i) =>
alist.toList(inputs).foldLeft(init) { (v, i) =>
i.processAttributes(v)(f)
}
}

View File

@ -16,7 +16,7 @@ object Util {
separate(ps)(Types.idFun)
def separate[T, A, B](ps: Seq[T])(f: T => Either[A, B]): (Seq[A], Seq[B]) = {
val (a, b) = ((Nil: Seq[A], Nil: Seq[B]) /: ps)((xs, y) => prependEither(xs, f(y)))
val (a, b) = ps.foldLeft((Nil: Seq[A], Nil: Seq[B]))((xs, y) => prependEither(xs, f(y)))
(a.reverse, b.reverse)
}

View File

@ -81,7 +81,7 @@ object JLineCompletion {
def convertCompletions(cs: Set[Completion]): (Seq[String], Seq[String]) = {
val (insert, display) =
((Set.empty[String], Set.empty[String]) /: cs) {
cs.foldLeft((Set.empty[String], Set.empty[String])) {
case (t @ (insert, display), comp) =>
if (comp.isEmpty) t
else (appendNonEmpty(insert, comp.append), appendNonEmpty(display, comp.display))

View File

@ -487,7 +487,7 @@ trait ParserMain {
/** Applies parser `p` to input `s`. */
def apply[T](p: Parser[T])(s: String): Parser[T] =
(p /: s)(derive1)
s.foldLeft(p)(derive1)
/** Applies parser `p` to a single character of input. */
def derive1[T](p: Parser[T], c: Char): Parser[T] =

View File

@ -170,10 +170,10 @@ object Logic {
}
private[this] def dependencyMap(clauses: Clauses): Map[Atom, Set[Literal]] =
(Map.empty[Atom, Set[Literal]] /: clauses.clauses) {
clauses.clauses.foldLeft(Map.empty[Atom, Set[Literal]]) {
case (m, Clause(formula, heads)) =>
val deps = literals(formula)
(m /: heads) { (n, head) =>
heads.foldLeft(m) { (n, head) =>
n.updated(head, n.getOrElse(head, Set.empty) ++ deps)
}
}
@ -305,7 +305,7 @@ object Logic {
case Clause(formula, head) +: tail =>
// collect direct positive and negative literals and track them in separate graphs
val (pos, neg) = directDeps(formula)
val (newPos, newNeg) = ((posDeps, negDeps) /: head) {
val (newPos, newNeg) = head.foldLeft((posDeps, negDeps)) {
case ((pdeps, ndeps), d) =>
(pdeps + (d, pos), ndeps + (d, neg))
}

View File

@ -85,7 +85,7 @@ object DotGraph {
private def relativized(roots: Iterable[File], path: File): String = {
val relativized = roots.flatMap(root => IO.relativize(root, path))
val shortest = (Int.MaxValue /: relativized)(_ min _.length)
val shortest = relativized.foldLeft(Int.MaxValue)(_ min _.length)
relativized.find(_.length == shortest).getOrElse(path.getName)
}
}

View File

@ -387,7 +387,7 @@ object Tests {
}
}
def overall(results: Iterable[TestResult]): TestResult =
((TestResult.Passed: TestResult) /: results) { (acc, result) =>
results.foldLeft(TestResult.Passed: TestResult) { (acc, result) =>
if (severity(acc) < severity(result)) result else acc
}
def discover(

View File

@ -105,7 +105,7 @@ object BasicCommands {
def help: Command = Command.make(HelpCommand, helpBrief, helpDetailed)(helpParser)
def helpParser(s: State): Parser[() => State] = {
val h = (Help.empty /: s.definedCommands)(
val h = s.definedCommands.foldLeft(Help.empty)(
(a, b) =>
a ++ (try b.help(s)
catch { case NonFatal(_) => Help.empty })
@ -319,7 +319,7 @@ object BasicCommands {
if (cp.isEmpty) parentLoader else toLoader(cp.map(f => new File(f)), parentLoader)
val loaded =
args.map(arg => ModuleUtilities.getObject(arg, loader).asInstanceOf[State => State])
(state /: loaded)((s, obj) => obj(s))
loaded.foldLeft(state)((s, obj) => obj(s))
}
def callParser: Parser[(Seq[String], Seq[String])] =

View File

@ -151,7 +151,7 @@ object Command {
def combine(cmds: Seq[Command]): State => Parser[() => State] = {
val (simple, arbs) = separateCommands(cmds)
state =>
(simpleParser(simple)(state) /: arbs.map(_ parser state))(_ | _)
arbs.map(_ parser state).foldLeft(simpleParser(simple)(state))(_ | _)
}
private[this] def separateCommands(

View File

@ -131,7 +131,7 @@ object Watched {
def multi(base: Watched, paths: Seq[Watched]): Watched =
new AWatched {
override def watchSources(s: State): Seq[Watched.WatchSource] =
(base.watchSources(s) /: paths)(_ ++ _.watchSources(s))
paths.foldLeft(base.watchSources(s))(_ ++ _.watchSources(s))
override def terminateWatch(key: Int): Boolean = base.terminateWatch(key)
override val pollInterval: FiniteDuration = (base +: paths).map(_.pollInterval).min
override val antiEntropy: FiniteDuration = (base +: paths).map(_.antiEntropy).min

View File

@ -3359,7 +3359,7 @@ object Classpaths {
}
def union[A, B](maps: Seq[A => Seq[B]]): A => Seq[B] =
a => (Seq[B]() /: maps) { _ ++ _(a) } distinct;
a => maps.foldLeft(Seq[B]()) { _ ++ _(a) } distinct;
def parseList(s: String, allConfs: Seq[String]): Seq[String] =
(trim(s split ",") flatMap replaceWildcard(allConfs)).distinct

View File

@ -326,7 +326,7 @@ ${listConflicts(conflicting)}""")
}
private[sbt] def and(a: Plugins, b: Plugins) = b match {
case Empty => a
case And(ns) => (a /: ns)(_ && _)
case And(ns) => ns.foldLeft(a)(_ && _)
case b: Basic => a && b
}
private[sbt] def remove(a: Plugins, del: Set[Basic]): Plugins = a match {

View File

@ -706,7 +706,7 @@ object Project extends ProjectExtra {
): Relation[ScopedKey[_], ScopedKey[_]] = {
val cMap = Def.flattenLocals(Def.compiled(settings, actual))
val emptyRelation = Relation.empty[ScopedKey[_], ScopedKey[_]]
(emptyRelation /: cMap) { case (r, (key, value)) => r + (key, value.dependencies) }
cMap.foldLeft(emptyRelation) { case (r, (key, value)) => r + (key, value.dependencies) }
}
def showDefinitions(key: AttributeKey[_], defs: Seq[Scope])(

View File

@ -48,7 +48,7 @@ object Tags {
}
private[this] final class Sum(tags: Seq[Tag], max: Int) extends Rule {
checkMax(max)
def apply(m: TagMap) = (0 /: tags)((sum, t) => sum + getInt(m, t)) <= max
def apply(m: TagMap) = tags.foldLeft(0)((sum, t) => sum + getInt(m, t)) <= max
override def toString = tags.mkString("Limit sum of ", ", ", " to " + max)
}
private[this] final class Or(a: Rule, b: Rule) extends Rule {

View File

@ -324,7 +324,7 @@ object BuildStreams {
resolvePath(projectPath(units, root, scoped, data), nonProjectPath(scoped))
def resolvePath(base: File, components: Seq[String]): File =
(base /: components)((b, p) => new File(b, p))
components.foldLeft(base)((b, p) => new File(b, p))
def pathComponent[T](axis: ScopeAxis[T], scoped: ScopedKey[_], label: String)(
show: T => String

View File

@ -65,7 +65,7 @@ private[sbt] object EvaluateConfigurations {
evaluateSbtFile(eval, src, IO.readLines(src), imports, 0)
}
loader =>
(LoadedSbtFile.empty /: loadFiles) { (loaded, load) =>
loadFiles.foldLeft(LoadedSbtFile.empty) { (loaded, load) =>
loaded merge load(loader)
}
}

View File

@ -68,7 +68,7 @@ object IvyConsole {
unmanaged: Seq[File]
)
def parseDependencies(args: Seq[String], log: Logger): Dependencies =
(Dependencies(Nil, Nil, Nil) /: args)(parseArgument(log))
args.foldLeft(Dependencies(Nil, Nil, Nil))(parseArgument(log))
def parseArgument(log: Logger)(acc: Dependencies, arg: String): Dependencies =
arg match {
case _ if arg contains " at " => acc.copy(resolvers = parseResolver(arg) +: acc.resolvers)

View File

@ -22,7 +22,7 @@ object KeyIndex {
projects: Map[URI, Set[String]],
configurations: Map[String, Seq[Configuration]]
): ExtendableKeyIndex =
(base(projects, configurations) /: known) { _ add _ }
known.foldLeft(base(projects, configurations)) { _ add _ }
def aggregate(
known: Iterable[ScopedKey[_]],
extra: BuildUtil[_],
@ -44,7 +44,7 @@ object KeyIndex {
}
(base(projects, configurations) /: toAggregate) {
case (index, Nil) => index
case (index, keys) => (index /: keys)(_ add _)
case (index, keys) => keys.foldLeft(index)(_ add _)
}
}
@ -84,7 +84,7 @@ object KeyIndex {
def keys(proj: Option[ResolvedReference], conf: Option[String], task: Option[AttributeKey[_]]) =
concat(_.keys(proj, conf, task))
def concat[T](f: KeyIndex => Set[T]): Set[T] =
(Set.empty[T] /: indices)((s, k) => s ++ f(k))
indices.foldLeft(Set.empty[T])((s, k) => s ++ f(k))
}
private[sbt] def getOr[A, B](m: Map[A, B], key: A, or: B): B = m.getOrElse(key, or)
private[sbt] def keySet[A, B](m: Map[Option[A], B]): Set[A] = m.keys.flatten.toSet
@ -241,7 +241,7 @@ private[sbt] final class KeyIndex0(val data: BuildIndex) extends ExtendableKeyIn
key: String
): Set[AttributeKey[_]] = keyIndex(proj, conf).tasks(key)
def keys(proj: Option[ResolvedReference]): Set[String] =
(Set.empty[String] /: optConfigs(proj)) { (s, c) =>
optConfigs(proj).foldLeft(Set.empty[String]) { (s, c) =>
s ++ keys(proj, c)
}
def keys(proj: Option[ResolvedReference], conf: Option[String]): Set[String] =
@ -270,7 +270,7 @@ private[sbt] final class KeyIndex0(val data: BuildIndex) extends ExtendableKeyIn
def addAggregated(scoped: ScopedKey[_], extra: BuildUtil[_]): ExtendableKeyIndex =
if (validID(scoped.key.label)) {
val aggregateProjects = Aggregation.aggregate(scoped, ScopeMask(), extra, reverse = true)
((this: ExtendableKeyIndex) /: aggregateProjects)(_ add _)
aggregateProjects.foldLeft(this: ExtendableKeyIndex)(_ add _)
} else
this

View File

@ -495,7 +495,7 @@ private[sbt] object Load {
unit.definitions.builds.flatMap(_.buildLoaders).toList match {
case Nil => loaders
case x :: xs =>
val resolver = (x /: xs) { _ | _ }
val resolver = xs.foldLeft(x) { _ | _ }
if (isRoot) loaders.setRoot(resolver) else loaders.addNonRoot(unit.uri, resolver)
}
@ -1069,7 +1069,7 @@ private[sbt] object Load {
case sf: DefaultSbtFiles => settings(defaultSbtFiles.filter(sf.include))
case p: AutoPlugins => autoPluginSettings(p)
case q: Sequence =>
(Seq.empty[Setting[_]] /: q.sequence) { (b, add) =>
q.sequence.foldLeft(Seq.empty[Setting[_]]) { (b, add) =>
b ++ expandSettings(add)
}
}
@ -1125,7 +1125,9 @@ private[sbt] object Load {
0
)(loader)
// How to merge SbtFiles we read into one thing
def merge(ls: Seq[LoadedSbtFile]): LoadedSbtFile = (LoadedSbtFile.empty /: ls) { _ merge _ }
def merge(ls: Seq[LoadedSbtFile]): LoadedSbtFile = ls.foldLeft(LoadedSbtFile.empty) {
_ merge _
}
// Loads a given file, or pulls from the cache.
def memoLoadSettingsFile(src: File): LoadedSbtFile =
@ -1145,7 +1147,7 @@ private[sbt] object Load {
case sf: SbtFiles => sf.files.map(f => IO.resolve(projectBase, f)).filterNot(_.isHidden)
case sf: DefaultSbtFiles => defaultSbtFiles.filter(sf.include).filterNot(_.isHidden)
case q: Sequence =>
(Seq.empty[File] /: q.sequence) { (b, add) =>
q.sequence.foldLeft(Seq.empty[File]) { (b, add) =>
b ++ associatedFiles(add)
}
case _ => Seq.empty

View File

@ -418,7 +418,7 @@ private[sbt] object PluginsDebug {
def allSettings(p: AutoPlugin): Seq[Setting[_]] =
p.projectSettings ++ p.buildSettings ++ p.globalSettings
val empty = Relation.empty[AutoPlugin, AttributeKey[_]]
(empty /: available)((r, p) => r + (p, extractDefinedKeys(allSettings(p))))
available.foldLeft(empty)((r, p) => r + (p, extractDefinedKeys(allSettings(p))))
}
private[this] def excludedError(transitive: Boolean, dependencies: List[AutoPlugin]): String =

View File

@ -156,7 +156,7 @@ object SessionSettings {
}
def removeRanges[T](in: Seq[T], ranges: Seq[(Int, Int)]): Seq[T] = {
val asSet = (Set.empty[Int] /: ranges) { case (s, (hi, lo)) => s ++ (hi to lo) }
val asSet = ranges.foldLeft(Set.empty[Int]) { case (s, (hi, lo)) => s ++ (hi to lo) }
in.zipWithIndex.flatMap { case (t, index) => if (asSet(index + 1)) Nil else t :: Nil }
}
@ -218,7 +218,7 @@ object SessionSettings {
val path = writeTo.getAbsolutePath
val (inFile, other, _) =
((List[Setting[_]](), List[Setting[_]](), Set.empty[ScopedKey[_]]) /: original.reverse) {
original.reverse.foldLeft((List[Setting[_]](), List[Setting[_]](), Set.empty[ScopedKey[_]])) {
case ((in, oth, keys), s) =>
s.pos match {
case RangePosition(`path`, _) if !keys.contains(s.key) => (s :: in, oth, keys + s.key)
@ -226,7 +226,7 @@ object SessionSettings {
}
}
val (_, oldShifted, replace) = ((0, List[Setting[_]](), Seq[SessionSetting]()) /: inFile) {
val (_, oldShifted, replace) = inFile.foldLeft((0, List[Setting[_]](), Seq[SessionSetting]())) {
case ((offs, olds, repl), s) =>
val RangePosition(_, r @ LineRange(start, end)) = s.pos
settings find (_._1.key == s.key) match {
@ -247,7 +247,7 @@ object SessionSettings {
val adjusted = if (newSettings.nonEmpty && needsTrailingBlank(exist)) exist :+ "" else exist
val lines = adjusted ++ newSettings.flatMap(x => x._2 :+ "")
IO.writeLines(writeTo, lines)
val (newWithPos, _) = ((List[SessionSetting](), adjusted.size + 1) /: newSettings) {
val (newWithPos, _) = newSettings.foldLeft((List[SessionSetting](), adjusted.size + 1)) {
case ((acc, line), (s, newLines)) =>
val endLine = line + newLines.size
((s withPos RangePosition(path, LineRange(line, endLine)), newLines) :: acc, endLine + 1)

View File

@ -37,7 +37,7 @@ object ExecuteSpec extends Properties("Execute") {
(i: Int, times: Int, workers: Int) =>
("Workers: " + workers) |: ("Value: " + i) |: ("Times: " + times) |: {
val initial = task(0) map (identity[Int])
def t = (initial /: (0 until times))((t, ignore) => t.map(_ + i))
def t = (0 until times).foldLeft(initial)((t, ignore) => t.map(_ + i))
checkResult(tryRun(t, false, workers), i * times)
}
}

View File

@ -116,7 +116,7 @@ object ConcurrentRestrictions {
m.updated(a, newb)
}
private[this] def merge[A, B](m: Map[A, B], n: Map[A, B])(f: (B, B) => B): Map[A, B] =
(m /: n) { case (acc, (a, b)) => update(acc, a, b)(f) }
n.foldLeft(m) { case (acc, (a, b)) => update(acc, a, b)(f) }
/**
* Constructs a CompletionService suitable for backing task execution based on the provided restrictions on concurrent task execution.

View File

@ -363,7 +363,7 @@ private[sbt] final class Execute[F[_] <: AnyRef](
val seen = IDSet.create[F[_]]
def visit(n: F[_]): List[F[_]] =
(seen process n)(List[F[_]]()) {
node :: (List[F[_]]() /: dependencies(n)) { (ss, dep) =>
node :: dependencies(n).foldLeft(List[F[_]]()) { (ss, dep) =>
visit(dep) ::: ss
}
}

View File

@ -131,7 +131,7 @@ object TestEvent {
}
private[sbt] def overallResult(events: Seq[TEvent]): TestResult =
((TestResult.Passed: TestResult) /: events) { (sum, event) =>
events.foldLeft(TestResult.Passed: TestResult) { (sum, event) =>
(sum, event.status) match {
case (TestResult.Error, _) => TestResult.Error
case (_, TStatus.Error) => TestResult.Error