Map-like function to return multiple values on each iteration in the loop
-
26-05-2021 - |
Question
Is there any sensible way of transforming this:
(for ([cos-t (stream-map cos t-range)]
[sin-t (stream-map sin t-range)])
...)
to something like this:
(for ([(cos-t sin-t) (... t-range)]
...)
It's not really a map function, since you can't make a list that way. I'm just looking for better and easier way of doing the thing above.
La solution
What you want is already available using the for
form. Use the in-parallel
function to combine two sequences in this way:
(for ([(cos-t sin-t) (in-parallel (stream-map cos t-range)
(stream-map sin t-range))])
(displayln (+ cos-t sin-t)))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow