Last active
August 9, 2018 14:15
-
-
Save giuliohome/007d25d53d939966f4271acca6d73862 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let rec bfs2 (fanout: Map<'node, 'node seq> -> 'node -> 'node seq) (tree: Map<'node, 'node seq>) (node: 'node) : 'node seq = | |
| let single = seq [node] | |
| match fanout tree node with | |
| | e when e = Seq.empty -> single | |
| | s -> Seq.fold (fun acc item -> | |
| bfs2 fanout tree item | |
| |> Seq.append acc) single s |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the above simpler code is valid if the map is guaranteed to be a tree without cycles,
otherwise, for a more robust but still functional implementation,look at https://gist.github.com/giuliohome/c9d4e4104e618d3cc94d2d09436c0952