Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transjuxt documentation and name unclear #26

Open
glfmnbw opened this issue Jul 31, 2018 · 2 comments
Open

transjuxt documentation and name unclear #26

glfmnbw opened this issue Jul 31, 2018 · 2 comments

Comments

@glfmnbw
Copy link

glfmnbw commented Jul 31, 2018

When I heard the name of transjuxt I assumed it could perform a transformation like so:

[[:a :b] [:a :b] [:a :b]] -> [[:a :a :a] [:b :b :b]]

Or act as if juxt defined a function:

((juxt (partial into [] (map inc))
          (partial into [] (map dec)))
 (range 100)

but using transjuxt inside the stack like so to avoid multiple traversals:

(into [] (transjuxt [(map inc) (map dec)]) (range 100))

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?

@cgrand
Copy link
Owner

cgrand commented Aug 2, 2018

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

@cgrand cgrand closed this as completed Aug 2, 2018
@cgrand cgrand reopened this Aug 2, 2018
@cgrand
Copy link
Owner

cgrand commented Aug 2, 2018

Note to self: review existing docstring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants