Skip to content

Instantly share code, notes, and snippets.

@carcigenicate
Created November 26, 2017 14:36
Show Gist options
  • Save carcigenicate/d5c766a0407def6ac81cb6775212b12e to your computer and use it in GitHub Desktop.
Save carcigenicate/d5c766a0407def6ac81cb6775212b12e to your computer and use it in GitHub Desktop.
I'd break this down step by step.
First, the keys of each map seem to be irrelevant, so we can get rid of them by `map`ping `vals` over your data (which I'll call `data`):
(map vals data)
(([{:ms "A", :s 1, :v 15}] [{:ms "A", :s 2, :v 18}] [{:ms "A", :s 4, :v 19}])
([{:ms "A", :s 1, :v2 5}] [{:ms "A", :s 2, :v2 8}] [{:ms "B", :s 4, :v2 9}]))
But that leaves some ugly nested lists. I removed them by using a 2D `map`:
(map #(map first %) data2) ; Could have also used partial
; Over each outer list, get the first element of each inner list
(({:ms "A", :s 1, :v 15} {:ms "A", :s 2, :v 18} {:ms "A", :s 4, :v 19})
({:ms "A", :s 1, :v2 5} {:ms "A", :s 2, :v2 8} {:ms "B", :s 4, :v2 9}))
The data looks much more manageable now. Lastly, I think we just need to `merge` each of the two lists of maps together:
(apply map merge data3))
; Apply each sublist to merge. This would be the same as deconstructing out each sublist, then writing (map merge sublist1 sublist2)
({:ms "A", :s 1, :v 15, :v2 5} {:ms "A", :s 2, :v 18, :v2 8} {:ms "B", :s 4, :v 19, :v2 9})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment