octopusgrabbus
octopusgrabbus

Reputation: 10695

How To Generate Multiple Calls To Function With One Arg In Sequence

I want to take a sequence [44 1 11] generated using (map #(nth %1 0 nil) v1) and feed (map) that into successive calls to the same function. I am just not sure which Clojure builtin or builtins to use other than for.

Here are the details.

Given these two vectors:

(def v1 [[44 2 3 4 5]
         [1 6 7 5 10]
         [11 12 13 14 15]])

(def v2 [[1 2 3 4 44]
         [1 6 7 5 1]
         [11 12 13 14 44]])

and this function

(defn ret-non-match-rows
    "Expects a sequence of sequences, like what is returned from clojure-csv.
     Returns all csv rows that do not match cmp-val at cmp-col-idx."

    [s-o-s cmp-val cmp-col-idx]

    (filter (complement nil?) 
       (map #(if (ret-col-match %1 cmp-val cmp-col-idx) nil %1) s-o-s) ))

So I am asking for help in how to feed (map) [44 1 11] into ret-non-match-rows like this

(ret-non-match-rows v2 44 4)
(ret-non-match-rows v2 44 1)
(ret-non-match-rows v2 44 11)

but using Clojure built-ins to generate those individual calls.

Thank You.

Edit:

The following gives me what I want, but I'm wondering if there is a cleaner way to do it.

(def ssn-1 [44 1 11])
(def tst (partial ret-non-match-rows v2 4))
(map #(tst %1) ssn-1)

I get back a sequence of sequences and will parse that to get my results.

Upvotes: 1

Views: 156

Answers (1)

Rafał Dowgird
Rafał Dowgird

Reputation: 45141

Maybe you want this:

(map (partial ret-non-match-rows v2 44) (map first v1))

(assuming the 4 in the first example call is a typo and should be 44)

Upvotes: 1

Related Questions