Created
June 24, 2015 10:29
-
-
Save adilakhter/0b3525e5ef29570f77a5 to your computer and use it in GitHub Desktop.
Fold on Binary Tree
This file contains 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 fold[A, B](t:Tree[A] , z:B)(f:(B,A,B) => B): B = t match { | |
case EmptyTree => z | |
case Node(x,l,r) => f ( fold( l , z )(f) , x , fold( r , z )(f) ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment