F#: Recursive collect and filter over N-ary Tree
Posted
by RodYan
on Stack Overflow
See other posts from Stack Overflow
or by RodYan
Published on 2010-05-11T23:54:22Z
Indexed on
2010/05/12
0:24 UTC
Read the original article
Hit count: 559
F#
|n-ary-tree
This is hurting my brain!
I want to recurse over a tree structure and collect all instances that match some filter into one list.
Here's a sample tree structure
type Tree =
| Node of int * Tree list
Here's a test sample tree:
let test =
Node((1,
[Node(2,
[Node(3,[]);
Node(3,[])]);
Node(3,[])]))
Collecting and filtering over nodes with and int value of 3 should give you output like this:
[Node(3,[]);Node(3,[]);Node(3,[])]
© Stack Overflow or respective owner