Doseq estimates 1 x for each y. Is there a way to get it to evaluate 1 x for 1 y and so on in Clojure?

I was not sure how to correctly name this thread, so if you can clarify it, do it.

My sample code is:

(doseq [x [1 2 3] y [3 2 1]] (println (str x y)))

The output of this code is:


13
12
11
23
22
21
33
32
31
nil

I understand that comprehension of the lists and the dose are so evaluated. Is there any other way to do this, so instead of 1 element from x is used for each element y, etc. 1 element from x is used with 1 element from y, etc., so instead, the output will be


13
22
31

Sorry, if I do not formulate this right, I just can not say it correctly.

EDIT: I think you can do it in Haskell with a list and a language extension. ParallelListComps or something like that.

+3
source share
3 answers

(doseq [[x y] (map vector [1 2 3] [3 2 1])] 
  (println (str x y)))
+11
(partition 2
  (interleave [1 2 3] [3 2 1]))

interleave , partition n.

+4

succint:

 (doall (map println [1 2 3] [3 2 1]))
+1
source

Source: https://habr.com/ru/post/1714123/


All Articles