meander

gdubs 2022-12-05T19:17:58.819679Z

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"?

xificurC 2022-12-05T19:19:22.038009Z

Can you give an example?

gdubs 2022-12-05T19:25:38.896669Z

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

gdubs 2022-12-05T19:25:43.217639Z

totally silly contrived example.

noprompt 2022-12-05T22:21:02.711309Z

@gdwarner 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.

noprompt 2022-12-05T22:23:59.051679Z

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

noprompt 2022-12-05T22:29:57.937669Z

(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