
Writing Elegant Clojure Code Using Higher-Order Functions - mblakele
http://christophermaier.name/2011/07/07/writing-elegant-clojure-code-using-higher-order-functions.html
======
praptak
My favorite example of brevity through higher order functions is:

    
    
        (defn flatt­en [x] (appl­y conca­t 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
This 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

------
ZackOfAllTrades
A rambling side note:

If you come from a javascript background, you will have a leg up on most
people in terms of learning clojure. You get used to inlining functions pretty
regularly.

What I am encountering as I chew through Programming Clojure though is that I
had no idea what I could have been doing in javascript all this time. I would
look at C and laugh about how they have to define an extra function for event
handling. It just seemed so verbose.

Looking back at the javascript I wrote/write, I really wish I had understood
what I could have been doing with functions, mappings, and apply. I
didn't/don't write javascript: it's just C with some in-lined functions.

Moral of the story: Inhale the Zen of
Crockford(<http://javascript.crockford.com/>) and exhale the suck of W3
schools.

~~~
psykotic
Please don't call them inlined functions. That has a very precise and very
different meaning in common usage, so you're likely to confuse a lot of
people.

~~~
brehaut
And to clarify, grandparent probably wants the terms 'first class function',
'anonymous function' or 'lambda' (depending on the specific usage.)

