minisql/src/main/scala/miniql/ast/Transform.scala

16 lines
367 B
Scala
Raw Normal View History

2024-07-20 20:43:20 +08:00
package minisql.ast
class Transform[T](p: PartialFunction[Ast, Ast]) extends StatelessTransformer {
override def apply(a: Ast) =
a match {
case a if (p.isDefinedAt(a)) => p(a)
case other => super.apply(other)
}
}
object Transform {
def apply[T](a: Ast)(p: PartialFunction[Ast, Ast]): Ast =
new Transform(p).apply(a)
}