Apply shorthand for each seq element

I have a list of lists, and I want to apply "decrease +" to each list in the collection. I think I should combine apply, map, and reduce +, but I can't figure out how to do this. Example:   [[1 2 3] [4 5 3] [2 5 1]] => [6 12 8]

+4
source share
1 answer

No need for apply. mapand reducewill work fine:

(map (partial reduce +) [[1 2 3] [4 5 3] [2 5 1]])

mapwill call a function for each member of the list, but partialsimply create a version with a reduced value of "curried", which expects one parameter. it can also be written as #(reduce + %)or(fn [lst] (reduce + lst))

Update

apply ( ):

(map (partial apply +) [[1 2 3] [4 5 3] [2 5 1]])

, . @AlexMiller

+4

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


All Articles