chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New egg: CHICKEN Transducers


From: Moritz Heidkamp
Subject: Re: New egg: CHICKEN Transducers
Date: Fri, 06 Jan 2023 14:38:24 +0100

Hi,

On  5 January 2023 18:48 -07, Jeremy Steward wrote:

> On 1/5/23 06:11, siiky wrote:
> I think the easiest way for this would be to just zip the list together:
>
>      (transduce list-fold
>                 (compose
>                   (zip-list lst2)
>                   (filter (lambda (p)
>                             (even? (* (car p) (cdr p))))))
>                 collect-list
>                 lst1)


FYI: Clojure's `sequence` function accepts varargs like `map` and also a
transducer which allows you to express this like so:

    (sequence (comp (map *) (filter odd?)) lst1 lst2)

The docstring describes it like this:

> When a transducer is supplied, returns a lazy sequence of applications
> of the transform to the items in coll(s), i.e. to the set of first
> items of each coll, followed by the set of second items in each coll,
> until any one of the colls is exhausted.  Any remaining items in other
> colls are ignored. The transform should accept number-of-colls
> arguments

I think you could offer the same API for `transduce`. Of course, you'll
have to adjust the `map` transducer accordingly, too.

Cheers
Moritz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]