feat(apb): add .flat() to access inner nodes

This commit is contained in:
əlemi 2024-05-20 01:56:32 +02:00
parent 39f6ff24b3
commit 756012ee69
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -116,6 +116,15 @@ impl<T : super::Base> Node<T> {
Node::Array(x) => x.iter().filter_map(Self::id).collect() Node::Array(x) => x.iter().filter_map(Self::id).collect()
} }
} }
pub fn flat(self) -> Vec<Node<T>> {
match self {
Node::Empty => vec![],
Node::Link(_) | Node::Object(_) => vec![self],
// i think AP disallows array of arrays so no need to make this recursive
Node::Array(arr) => arr.into()
}
}
} }
#[cfg(feature = "unstructured")] #[cfg(feature = "unstructured")]