You could even turn this into an extension method, so that you can write `tree.flattenBFS.map(...)`