First Class functions
Idempotent - given the same input you get the same output
(+ 1 2 3 4 5 6 7 8 9 10)
Note
The range
function generates a sequence of numbers and when given arguments it does so from a specific range. The second number is exclusive, so for 1 to 10 the second argument should be 11.
(range 1 11)
Unfortunately we cant just add the result of a range, because it returns a lazy sequence So (range)
by itself will create an error
(+ 1 (range 1 11))
Using a function called reduce
we can calculate a single total value from all the numbers in the collection.
The reduce function take 2 arguments, the first is the function to apply to a data structure, the second is the data structure.
(reduce + (range 1 11))
(reduce + (1 2 3 4 5 6 7 8 9 10))