@slack1 in-parallel
allows one line in a for*/fold
to efficiently iterate over more than one sequence at once: (for*/fold ([best 0] [seen-at 0] #:result (list best seen-at))
([(t index) (in-parallel (in-list tuples) (in-naturals))]
[now (in-value (log-identity (first t) (second t)))]
#:when (< best now))
(values now index))
if you’re just wanting to include natural-number indices, in-indexed
can be useful as well (i.e. instead of in-parallel
and in-naturals
, which is equivalent): (for*/fold ([best 0] [seen-at 0] #:result (list best seen-at))
([(t index) (in-indexed (in-list tuples))]
[now (in-value (log-identity (first t) (second t)))]
#:when (< best now))
(values now index))
also minor FYI in case you were unaware, using in-list
(or whatever appropriate in-
form to iterate over a sequence) will be a lot more efficient than relying on dynamic dispatch to figure out what kind of sequence it is (in your example tuples
was relying on dynamic dispatch)