rfmind
rfmind

Reputation: 58

Something built-in in clojure for --> call an impure function to each element in a sequence?

I was wondering if clojure has something built-in for the following code. I know I can do (map (fn [x] (f x)) coll) and then evaluate the sequence as done here. I don't want to do that.

(defn apply-to-all [f coll]
  (f (first coll))
  (if (= (count (rest coll)) 0) 
    nil
    (apply-to-all f (rest coll))))

"example usage"
(apply-to-all println [0 1 2])

Upvotes: 1

Views: 70

Answers (1)

user1804599
user1804599

Reputation:

(doseq [x [0 1 2]]
  (println x))

Upvotes: 3

Related Questions