From 756012ee696cd5cb2ff3ff82425857f68c5ffb0d Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 20 May 2024 01:56:32 +0200 Subject: [PATCH] feat(apb): add .flat() to access inner nodes --- apb/src/node.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apb/src/node.rs b/apb/src/node.rs index c1244e9..d8b427a 100644 --- a/apb/src/node.rs +++ b/apb/src/node.rs @@ -116,6 +116,15 @@ impl Node { Node::Array(x) => x.iter().filter_map(Self::id).collect() } } + + pub fn flat(self) -> Vec> { + 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")]