Skip to content

Instantly share code, notes, and snippets.

@adilakhter
Created June 24, 2015 10:29
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 adilakhter/0b3525e5ef29570f77a5 to your computer and use it in GitHub Desktop.
Save adilakhter/0b3525e5ef29570f77a5 to your computer and use it in GitHub Desktop.
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