Just now, Carl Eastlund wrote:
> You can also write:
>
> (for*/list ([(k v) (in-hash ht)]
> [res (in-value (f k v))]
> #:when res)
> res)
[It does seem a little too verbose with the 3 mentions of `res', but
that's the same kind of verbosity as repeating `x' in:
(for/l
You can also write:
(for*/list
([(k v) (in-hash ht)]
[res (in-value (f k v))]
#:when res)
res)
The in-value sequence "lifts" values to length-one sequences for just
such kinds of bindings. (The above is untested, so may need some
fixing.)
Carl Eastlund
On Tue, Sep 6, 2011 at 2:35 PM,
When writing a natural extension to racket/base for hashes, hash-filter-map, I
found that what would be the most natural way to write it would look like so:
(define (hash-filter-map f ht)
(for/list ([(k v) (in-hash ht)]
#:when/bind [res (f k v)])
res))
Instead I had to write
3 matches
Mail list logo