Fork me on GitHub
#babashka
<
2023-02-13
>
Matthew Twomey04:02:58

I want this same result:

(->> {:one "one" :two "two" :three "three"} vec flatten) 
;; => (:one "one" :two "two" :three "three")
I feel like I might be missing a single function that does this?

Matthew Twomey04:02:43

(mapcat seq {:one "one" :two "two" :three "three"}) also does it - but still seems like it should be more simple.

dpsutton04:02:53

iterleave its keys and values. but be aware that you are going from an unordered structure to an ordered one. The way you "see" the map or think it should order might not be what you end up with.

Matthew Twomey04:02:43

well, what I do care about is that the pairs stay next to each other. I don’t care about the order of the pairs themselves.

dpsutton04:02:09

good. then (defn as-seq [m] (interleave (keys m) (vals m))) should do it for you

dpsutton04:02:57

although nothing really wrong with your mapcat seq solution

Matthew Twomey04:02:29

Oh yeah - ok, cool. I’m finding lots of ways to do this I see. I haven’t run into interleave yet - thanks for pointing it out!

👍 1
dpsutton04:02:24

(into [] cat {:one "one" :two "two" :three "three"})

👀 1
1