From cb19875c5d94150b83e3c61e19d80958ec1e9c41 Mon Sep 17 00:00:00 2001 From: Manos Koukoutos <emmanouil.koukoutos@epfl.ch> Date: Thu, 21 Apr 2016 11:28:38 +0200 Subject: [PATCH] map* -> flatMap* in ExamplesBank --- src/main/scala/leon/repair/rules/Focus.scala | 4 ++-- src/main/scala/leon/synthesis/ExamplesBank.scala | 10 +++++----- .../scala/leon/synthesis/rules/IndependentSplit.scala | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/scala/leon/repair/rules/Focus.scala b/src/main/scala/leon/repair/rules/Focus.scala index e1f2f0cbd..99a248d70 100644 --- a/src/main/scala/leon/repair/rules/Focus.scala +++ b/src/main/scala/leon/repair/rules/Focus.scala @@ -165,7 +165,7 @@ case object Focus extends PreprocessingRule("Focus") { } val eb3 = if (vars.nonEmpty) { - eb2.mapIns(ebF) + eb2.flatMapIns(ebF) } else { eb2.eb } @@ -243,7 +243,7 @@ case object Focus extends PreprocessingRule("Focus") { }.toList } - val np = Problem(p.as, ws(body), p.pc withBinding (id -> value), p.phi, p.xs, qeb.mapIns(ebF)) + val np = Problem(p.as, ws(body), p.pc withBinding (id -> value), p.phi, p.xs, qeb.flatMapIns(ebF)) Some(decomp(List(np), termWrap(Let(id, value, _)), s"Focus on let-body")(p)) diff --git a/src/main/scala/leon/synthesis/ExamplesBank.scala b/src/main/scala/leon/synthesis/ExamplesBank.scala index e8d831a5c..ad75eaace 100644 --- a/src/main/scala/leon/synthesis/ExamplesBank.scala +++ b/src/main/scala/leon/synthesis/ExamplesBank.scala @@ -76,7 +76,7 @@ case class ExamplesBank(valids: Seq[Example], invalids: Seq[Example]) { } /** Expands each input example through the function f */ - def mapIns(f: Seq[Expr] => List[Seq[Expr]]) = { + def flatMapIns(f: Seq[Expr] => List[Seq[Expr]]) = { map { case InExample(in) => f(in).map(InExample) @@ -87,7 +87,7 @@ case class ExamplesBank(valids: Seq[Example], invalids: Seq[Example]) { } /** Expands each output example through the function f */ - def mapOuts(f: Seq[Expr] => List[Seq[Expr]]) = { + def flatMapOuts(f: Seq[Expr] => List[Seq[Expr]]) = { map { case InOutExample(in, out) => f(out).map(InOutExample(in, _)) @@ -174,14 +174,14 @@ case class QualifiedExamplesBank(as: List[Identifier], xs: List[Identifier], eb: val nxs = xs.filterNot(toRemove) val toKeep = xs.zipWithIndex.filterNot(x => toRemove(x._1)).map(_._2) - QualifiedExamplesBank(as, nxs, eb mapOuts { out => List(toKeep.map(out)) }) + QualifiedExamplesBank(as, nxs, eb flatMapOuts { out => List(toKeep.map(out)) }) } def removeIns(toRemove: Set[Identifier]) = { val nas = as.filterNot(toRemove) val toKeep: List[Int] = as.zipWithIndex.filterNot(a => toRemove(a._1)).map(_._2) - QualifiedExamplesBank(nas, xs, eb mapIns { (in: Seq[Expr]) => List(toKeep.map(in)) }) + QualifiedExamplesBank(nas, xs, eb flatMapIns { (in: Seq[Expr]) => List(toKeep.map(in)) }) } /** Filter inputs through expr which is an expression evaluating to a boolean */ @@ -192,7 +192,7 @@ case class QualifiedExamplesBank(as: List[Identifier], xs: List[Identifier], eb: /** Filters inputs through the predicate pred, with an assignment of input variables to expressions. */ def filterIns(pred: Map[Identifier, Expr] => Boolean): QualifiedExamplesBank = { QualifiedExamplesBank(as, xs, - eb mapIns { in => + eb flatMapIns { in => val m = (as zip in).toMap if(pred(m)) { List(in) diff --git a/src/main/scala/leon/synthesis/rules/IndependentSplit.scala b/src/main/scala/leon/synthesis/rules/IndependentSplit.scala index 41d4c24b2..6c7c09041 100644 --- a/src/main/scala/leon/synthesis/rules/IndependentSplit.scala +++ b/src/main/scala/leon/synthesis/rules/IndependentSplit.scala @@ -53,7 +53,7 @@ case object IndependentSplit extends NormalizingRule("IndependentSplit") { val newOuts = subOuts.flatten - val newEb = p.qeb.eb.mapOuts{ xs => List( (xs zip p.xs) flatMap { + val newEb = p.qeb.eb.flatMapOuts{ xs => List( (xs zip p.xs) flatMap { case (CaseClass(_, args), id) if isDecomposable(id) => args.toList case (Tuple(args), _) => args.toList case (other, _) => List(other) -- GitLab