Skip to content
Snippets Groups Projects
Commit 161be27f authored by Régis Blanc's avatar Régis Blanc
Browse files

use preMapWithContext to implement preMap

parent 9215b774
No related branches found
No related tags found
No related merge requests found
...@@ -133,23 +133,8 @@ trait GenTreeOps[SubTree <: Tree] { ...@@ -133,23 +133,8 @@ trait GenTreeOps[SubTree <: Tree] {
* @note The mode with applyRec true can diverge if f is not well formed * @note The mode with applyRec true can diverge if f is not well formed
*/ */
def preMap(f: SubTree => Option[SubTree], applyRec : Boolean = false)(e: SubTree): SubTree = { def preMap(f: SubTree => Option[SubTree], applyRec : Boolean = false)(e: SubTree): SubTree = {
val rec = preMap(f, applyRec) _ def g(t: SubTree, u: Unit): (Option[SubTree], Unit) = (f(t), ())
preMapWithContext[Unit](g, applyRec)(e, ())
val newV = if (applyRec) {
// Apply f as long as it returns Some()
fixpoint { e : SubTree => f(e) getOrElse e } (e)
} else {
f(e) getOrElse e
}
val Deconstructor(es, builder) = newV
val newEs = es.map(rec)
if ((newEs zip es).exists { case (bef, aft) => aft ne bef }) {
builder(newEs).copiedFrom(newV)
} else {
newV
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment