Skip to content

Instantly share code, notes, and snippets.

@IvanVergiliev
Created June 17, 2021 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IvanVergiliev/95ca2fc48cdda1719c874d6d84263bb8 to your computer and use it in GitHub Desktop.
Save IvanVergiliev/95ca2fc48cdda1719c874d6d84263bb8 to your computer and use it in GitHub Desktop.
Tree Transformation Algorithm with Code Reuse
def transformTree(tree: Tree): Option[Tree] = {
// Notice that there's no `canTranform` - we're using
// `transform().isDefined` to check for transformability!
  val transformedLeft = if (transform(tree.left).isDefined) {
    transform(tree.left)
} else None
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment