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

Add values-oriented zip to qi/list #183

Open
countvajhula opened this issue Oct 15, 2024 · 2 comments
Open

Add values-oriented zip to qi/list #183

countvajhula opened this issue Oct 15, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@countvajhula
Copy link
Collaborator

This problem was posed by @soegaard on Discord:

How would you write the following?

The function f is mapped over a list (list x0 x1 ...).
Each call returns two values (in the code called a and b).
These values are collected and the final result is
(values (list a0 a1 ...) (list b0 b1 ...)
where ai and bi are the result of calling (f xi).

It would be nice if the following worked:

(require qi qi/list)
(~> (1 2 3) (>< (~> f ▽)) zip)

Note this version is slightly different from the original posed question in that it accepts values directly rather than a list of values. Likewise, the zip should yield multiple lists as independent values, rather than a single list containing them all.

(@benknoble suggested the introduction of a values-oriented form analogous to by that would allow for a different solution here -- this form also sounds like it would be a good addition, to qi core rather than qi/list).

@countvajhula countvajhula added the enhancement New feature or request label Oct 15, 2024
@benknoble
Copy link
Collaborator

So is zip as proposed something like (-> (list/c x ...) ... (values (list/c x ...) ...)), transposing?

Said another way, if we make a table like

values 1 | 2 | 3
   a     | b | c
   d     | e | f

Then zip takes (values '(a d) '(b e) '(c f)) and transposes to (values '(a b c) '(d e f))? I think I see how that's like Python's zip.

@countvajhula
Copy link
Collaborator Author

Yes, I think many languages provide some form of zip, including Python, Haskell, and Ruby. The zip proposed here would be the same except returning separate values instead of a list.

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

No branches or pull requests

2 participants