Idiomatic way to iterate through all pairs of a collection in Clojure

Given a collection I want to iterate through all pairs in a collection. Example

(all-pairs seq)

(all-pairs '(a b c d)) => ([a b] [a c] [a d] [b c] [b d] [c d]))

Here is my idea

(defn all-pairs [coll]
  (for [ [idx elmt] (indexed coll)
         other-elmt (subvec coll (inc idx))]
     (vector elmt other-elm)))

But it doesn't feel idiomatic

17
задан Cœur 3 September 2017 в 15:27
поделиться