yegor256
yegor256

Reputation: 105043

how to apply a two-arg function to a sequence?

I have a sequence:

[a b c ...]

And a function (f x y). I want to get this:

(f c (f b (f a 1)))

Etc.. How to do this?

Upvotes: 5

Views: 107

Answers (2)

Rafał Dowgird
Rafał Dowgird

Reputation: 45071

Reduce, with a small adaptation:

(reduce #(f %2 %1) 1 [a b c])

Upvotes: 11

ponzao
ponzao

Reputation: 20934

(reduce (fn [acc x] (f x acc)) 1 [a b c d])

Upvotes: 2

Related Questions