Fork me on GitHub
#specter
<
2017-12-14
>
abdullahibra11:12:54

for this data:

abdullahibra11:12:04

[{:s1 "cool", :p1 [{:name "hello", :sen "good"} {:name "world", :sen "nothing"}]} {:s2 "cool2", :p1 [{:name "wow", :sen "fine"} {:name "world", :sen "none"}]}][{:s1 "cool", :p1 [{:name "hello", :sen "good"} {:name "world", :sen "nothing"}]}]

abdullahibra11:12:36

i want to get only hash maps which contain :name "world" and :sen "nothing"

abdullahibra11:12:55

(select [ALL (selected? :p1 ALL (multi-path :token :sen) [#(= "world" (:name %)) #(= "nothing" (:sen %))])] data)

nathanmarz13:12:37

@abdullahibra (select [ALL (selected? :p1 ALL #(= (:name %) "world") #(= (:sen %) "nothing"))] data)

abdullahibra13:12:49

thanks man 🙂, your video is very worthwhile i have watched it

nathanmarz14:12:19

it's pretty out of date though, my blog post is the best introductory resource

benstox14:12:54

Hi there, a question about walkers. If I have a data structure like this and I want to get all the leaves that have more than just whitespace in them, but still return the structure where they live:

(def structure [
  "leaf1"
  "\n"
  {:contents [
    {:contents ["leaf3"]}
    {:contents [
      {:contents [
        "leaf5"
        "leaf6"
        "\n"]}]}
    "\n"
    {:contents [
      "\n"
      "\n"]}]}
  {:contents [
    "leaf2"
    {:contents []}]}
  "leaf4"])
So I’d hope to return a structure like this:
[
  "leaf1"
  {:contents [
    {:contents ["leaf3"]}
    {:contents [
      {:contents [
        "leaf5"
        "leaf6"]}]}]}
  {:contents ["leaf2"]}
  "leaf4"]
I can get all the right leaves but not the structure with this:
(select [(walker #(and (string? %) (re-find #"\S" %)))] structure)
I thought maybe filterer would be the right tool for this but couldn’t get it to work. Am I going about this the right way?

nathanmarz15:12:05

@benstox the right approach is to do a transform and remove elements that have whitespace

nathanmarz15:12:15

don't use walker

nathanmarz15:12:56

(def NODES
  (recursive-path [] p
    (continue-then-stay
      (cond-path vector? [ALL p]
                 map? [MAP-VALS p])
      )))

(defn whitespace? [s] (= "\n" s))

(setval [NODES (if-path string? whitespace? empty?)] NONE structure)

nathanmarz15:12:43

just fill in whitespace? with a complete implementation

benstox15:12:26

I see. Thanks a lot! I’ll try something like that.