forked from alemi/upub
feat(apb): add .flat() to access inner nodes
This commit is contained in:
parent
39f6ff24b3
commit
756012ee69
1 changed files with 9 additions and 0 deletions
|
@ -116,6 +116,15 @@ impl<T : super::Base> Node<T> {
|
|||
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")]
|
||||
|
|
Loading…
Reference in a new issue