Fork me on GitHub
#meander
<
2022-12-05
>
gdubs19:12:58

If I want to transform the same data in two ways, should I just run two operations? Or can I have a single operation with two "right hand sides"?

xificurC19:12:22

Can you give an example?

gdubs19:12:38

Sorry for the screenshot. I literally don't know how to copy and paste out of my remote editor.

gdubs19:12:43

totally silly contrived example.

noprompt22:12:02

@UG9CG9GDB Two seems right in this case. The first query is a join and the second is not. In the second you do not need to look for {:id ?team} though.

noprompt22:12:59

Depending on the project, it might be a good idea to index the teams by :id first.

noprompt22:12:57

(let [data {:people [{:name "greg", :team 1} {:name "jill" :team 2}]
            :teams [{:id 1 :name "stars"} {:id 2 :name "fish"} {:id 3 :name "dogs"}]}
      teams (:teams data)
      people (:people data)
      team-idx (into {} (map (juxt :id identity)) teams)]
  {:players (m/search [people team-idx]
              [(m/scan {:name ?name, :team ?team-id})
               {?team-id {:name ?team}}]
              {:name ?name :team ?team})
   :teams (map :name teams)})

👍 1