Open glfmnbw opened 6 years ago
transjuxt
ever produces only one value made of the first value produced by each of its transducers arguments:
.
=> (into [] (x/transjuxt [(map first) (map second)]) [[:a :b] [:a :b] [:a :b]])
[[:a :b]]
; unexpected, let's see which :a and :b we are talking about:
=> (into [] (x/transjuxt [(map first) (map second)]) [[:a :b] [:c :d] [:e :f]])
[[:a :b]]
; ok the first ones (as explained above)
; if we want to get all values for each map we have to collect them with x/into:
=> (into [] (x/transjuxt [(comp (map first) (x/into [])) (comp (map second) (x/into []))]) [[:a :b] [:a :b] [:a :b]])
[[[:a :a :a] [:b :b :b]]]
; ok but we have an extra nesting due to the top-level into [], let's use x/some!
=> (x/some (x/transjuxt [(comp (map first) (x/into [])) (comp (map second) (x/into []))]) [[:a :b] [:a :b] [:a :b]])
[[:a :a :a] [:b :b :b]]
; but in this case it's just simpler to call transjuxt with two arguments (xforms and items source):
=> (x/transjuxt [(comp (map first) (x/into [])) (comp (map second) (x/into []))] [[:a :b] [:a :b] [:a :b]])
[[:a :a :a] [:b :b :b]]
Hope this helps
Note to self: review existing docstring
When I heard the name of transjuxt I assumed it could perform a transformation like so:
Or act as if
juxt
defined a function:but using transjuxt inside the stack like so to avoid multiple traversals:
However, I can't get it to behave this way. I can't tell if I've misunderstood its use and purpose, or if I have called it wrong.
Can you add an example to the documentation of what it's output might look like in practice and how to call it?