fork download
  1. (defn grep-n [n pred coll]
  2. (->> coll
  3. (map-indexed (fn [i x] (clojure.lang.MapEntry. i x)))
  4. (partition (-> n (* 2) inc) 1)
  5. (filter #(-> % (nth n) val pred))
  6. (apply concat)
  7. distinct
  8. (map val)))
  9.  
  10. (->> (range 1000)
  11. (grep-n 3 #{1 2 998 999})
  12. print)
Success #stdin #stdout 1.14s 77036KB
stdin
Standard input is empty
stdout
()