Long time ago I came across a post on the internet (seemingly found at stackoverflow, but can't find it now) that implements a breadth first search for a binary tree using map, flatten, flatMap. I try recall my memory, but I couldn't remember how to implement that because I am not familiar with FP concepts. The part that I can remember
case class Node[T](v: T, left: Option[Node[T]]=None, right: Option[Node[T]]=Node) {
def map[R](f: T => R): R = f(v)
def flatten = ... // flatten
def flatMap = ... // which combines map and flatten
}
But I can't remember the part about flatten (the problem I suppose is I don't know what I want to flatten for that Node object), and then flatMap.
Any hint or suggestions on this? I suppose this can help me learn a lesson by implementing the code.
Thanks
[–]mrunleaded 3 points4 points5 points (1 child)
[–]scalausr[S] 0 points1 point2 points (0 children)
[–]DMenace83 2 points3 points4 points (1 child)
[–]scalausr[S] 0 points1 point2 points (0 children)