Created
June 17, 2021 20:35
-
-
Save IvanVergiliev/95ca2fc48cdda1719c874d6d84263bb8 to your computer and use it in GitHub Desktop.
Tree Transformation Algorithm with Code Reuse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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