Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- implicit object TreeFoldLeft extends FoldLeft[Tree] {
- def foldLeft[A, B](ma: Tree[A], b: B, op: (B, A) => B) = {
- def toList(ma: Tree[A]): List[A] = ma match {
- // not the fastest implementation ever
- case Node(el, left, right) => toList(left) ::: (el :: toList(right))
- case Empty() => Nil
- }
- toList(ma).foldLeft(b)(op)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment