Fold on Binary Tree
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