The code snippet you provided is written in Clojure, a dialect of Lisp. The 
function filter-collecting takes a predicate function, a collector 
function, and multiple lists as arguments. It filters the lists based on 
the predicate function and collects the values from the corresponding 
positions in the lists using the collector function. Copied 
from https://fiverrme.com/

(filter-collecting
  (fn [x y] (< x y))      ; predicate function: checks if x < y
  (fn [x y] (+ x y))      ; collector function: adds x and y
  '(1 7 3 9)              ; first list
  '(5 5 5 5))             ; second list

The first list is (1 7 3 9) and the second list is (5 5 5 5). The function 
checks if each corresponding pair of elements from the two lists satisfies 
the predicate function (x < y). In this case, the pairs (1 5) and (3 5) 
satisfy the predicate because 1 is less than 5 and 3 is less than 5.

For the pairs that satisfy the predicate, the collector function (+) is 
applied to the corresponding elements. The sum of (1 5) is 6, and the sum 
of (3 5) is 8.

Therefore, the result of (filter-collecting (fn [x y] (< x y)) (fn [x y] (+ 
x y)) '(1 7 3 9) '(5 5 5 5)) is (6 8).
On Friday, 14 August 2009 at 18:42:39 UTC-7 Fogus wrote:

> > (defn filter-collecting [predicate collector & lists]
> >   (for [v (apply map vector lists) :when (apply predicate v)] (apply
> > collector v)))
>
> This is very nice. It's short, sweet, and actually describes the
> functionality.
>
> -m
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/b4463e90-de8c-43a9-91fb-b8317af10ec3n%40googlegroups.com.

Reply via email to