Is there a way I can generate multiple values in for/list during each iteration and have the results "flattened"?
For instance:
(for/list ([i (range n)]) (values i (+ i 1)))
I'd like the result to be (list 0 1 1 2 2 3 3 4 ...).
This question is very much relevant to https://github.com/racket/racket/pull/2483. In the link, you will find:
(for/append-list ([i (range n)]) (list i (+ i 1))).(for/list* ([i (range n)]) (values i (+ i 1))) (with caveat, see the link for more details).But since these don't exist in Racket yet, the easiest way to get what you want is:
(append* (for/list ([i (range n)]) (list i (+ i 1))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With