minisql/src/main/scala/miniql/ast/Transform.scala
2024-07-20 20:43:20 +08:00

15 lines
367 B
Scala

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)
}