Hello everyone,

I have a question about creating a steam that yields multiple values on
each iteration. Given something like:

(require racket/strema)

(define my-stream (for/stream ([i (in-range 1 10)])
                    (values "hi" i)))

When I'm trying to:

(let-values ([(a b) (stream-ref my-stream 0)])
    (printf "~v: ~v" a b))

I'm getting:

; result arity mismatch;
;  expected number of values not received
;   expected: 1
;   received: 2
;   values...:
;    "hi"
;    2
; Context:
;  
/nix/store/z4mpvw1p6whq454lmjshbdr6472sdbr3-racket-7.6/share/racket/collects/racket/repl.rkt:11:26

Similarly:

(for ([(a b) my-stream])
    (printf "~v: ~v" a b))

leads to:

; result arity mismatch;
;  expected number of values not received
;   expected: 1
;   received: 2
;   values...:
;    "hi"
;    1
; Context:
;  tcp-accepted:1:1 for-loop
;  top-level:1:1 [running body]
;  
/nix/store/z4mpvw1p6whq454lmjshbdr6472sdbr3-racket-7.6/share/racket/collects/racket/repl.rkt:11:26

Documentation on stream-ref specifically mentions that it can have
multiple values:
https://docs.racket-lang.org/reference/streams.html?q=stream-ref#%28def._%28%28lib._racket%2Fstream..rkt%29._stream-ref%29%29

What am I doing wrong here?

P.S. The context is that I'm trying to create a function that would
return results from an API as a stream that can be iterated with the for
family of forms, and would yield multiple values per iteration.

--
Yury Bulka
https://mamot.fr/@setthemfree
#NotOnFacebook

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/87ftcineuk.fsf%40privacyrequired.com.

Reply via email to