3 ms·
My favorite example of brevity through higher order functions is: (defn flatten [x] (apply concat x)) It flattens one-level of nested lists ( like [[1
by praptak 15y ago
My favorite example of brevity through higher order functions is:
(defn flatten [x] (apply concat x))
It flattens one-level of nested lists ( like [[1 2] [3 4]] -> [1 2 3 4]) and even works when x is an infinite generated sequence. On the other hand brevity is not always clarity so HOF tricks should be treated with caution.
- nickik 15y agoThis is a nice function but 1) This only works if everything is really a seq so [[1 2][3 4] 5] does not work 2) the name is not optimal