Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement deep wildcard operation #8

Merged
merged 1 commit into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions spec/expressions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ tests:
price: 8.99


# - desc: path with deep wildcards collects all values regardless its level
# scope:
# <<: *goessner
# template:
# prices: $ store.**.price
# result:
# prices:
# - 8.95
# - 12.99
# - 8.99
# - 22.99
# - 19.95
# - 1.3
- desc: path with deep wildcards collects all values regardless its level
scope:
<<: *goessner
template:
prices: $ store.**.price
result:
prices:
- 8.95
- 12.99
- 8.99
- 22.99
- 19.95
- 1.3

- desc: path with multiple wildcards returns array of values
scope:
Expand Down
8 changes: 8 additions & 0 deletions src/jute/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,14 @@ string-literal
(vec (filter #(compiled-pred (assoc scope :this %)) val)))
true])

(= :path-deep-wildcard t) [(fn [val scope is-multiple?]
(->> (if is-multiple? val [val])
(mapcat (partial tree-seq
(some-fn map? vector?)
#(if (map? %) (vals %) %)))
(remove nil?)))
true]

:else

[(let [compiled-expr (compile-expression-ast cmp options path)]
Expand Down