Skip to content

Commit

Permalink
feat: pluck-deep handles missing properties
Browse files Browse the repository at this point in the history
  • Loading branch information
line-o committed Mar 19, 2021
1 parent be571a8 commit 2ec8681
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/content/xbow.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ function xbow:pluck-deep ($fields as xs:anyAtomicType*) as item()* {

declare
function xbow:pluck-deep ($map-or-array-or-node as item(), $fields as xs:anyAtomicType*) as item()* {
fold-left($fields, $map-or-array-or-node, xbow:pluck#2)
fold-left($fields, $map-or-array-or-node, function ($eventual-item as item()*, $field) {
if (exists($eventual-item))
then (xbow:pluck($eventual-item, $field))
else ()
})
};

(: stats :)
Expand Down
21 changes: 8 additions & 13 deletions src/test/xbow-spec.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,17 @@ function xbow-spec:array-group-by-even-odd-accessor () {
declare
%test:assertEquals(1)
function xbow-spec:pluck-deep () {
map {
'a': map {
'b': map {
'c': map {
'd': map {
'e': map {
'f': 1
}
}
}
}
}
}
map {'a': map {'b': map {'c': map {'d': map {'e': map {'f': 1 }}}}}}
=> xbow:pluck-deep(('a','b','c','d','e','f'))
};

declare
%test:assertEmpty
function xbow-spec:pluck-deep-non-existent-field () {
map {'a': map {'b': map {'c': map {'d': map {'e': map {'f': 1 }}}}}}
=> xbow:pluck-deep(('a','b','c', 1, 'd','e','f'))
};


declare
%test:assertEquals(9)
Expand Down

0 comments on commit 2ec8681

Please sign in to comment.