
Higher-Order Functions in JavaScript - zatkin
http://eloquentjavascript.net/05_higher_order.html
======
drderidder
I recently read this, worked through the examples, and was pleasantly
surprised at the depth and quality. Subsequently we recommended it to our 800+
member meetup group as the top learning resource for new JS programmers. The
content is enlightening and enjoyable and could be just the thing for reaching
a breakthrough in understanding about functional programming.

~~~
heatish
Eloquent Javascript was the first programming book that I ever worked through
online and subsequently went and bought because I was so happy with it. I was
young and playing Diablo 2: LoD and stumbled upon some bot that would let me
do Mephisto runs for loot all night, I was amazed with it and went back to the
forums where I'd found it and did some reading, this was the book that they
recommended for anyone who was interested in learning some programming.

I'd have to say that this book was one of the more gentle and concise
introductory books I've ever read and so far I couldn't be happier that it was
my personal introduction to JS and programming. It certainly set me leaps
ahead in the JS section when I attended a web dev bootcamp. It is my personal
go to for any of my friends who approach me about their interest in getting
started with programming. Big Nerd Ranch books are a close second but I've
only recently found them and begun reading them.

~~~
mauz
I profoundly appreciate the nostalgia you brought back by talking about
Mephisto runs.

------
zatkin
It's also worth mentioning Lodash[1] if you're new to this idea of functional
programming. They have an awesome description of each function name and
they're very closely aligned to the functional terminology.

[1] - [http://lodash.com/docs](http://lodash.com/docs)

~~~
dominotw
Also this ? [http://ramdajs.com/](http://ramdajs.com/)

~~~
masklinn
Also this: [http://facebook.github.io/immutable-
js/docs/#/](http://facebook.github.io/immutable-js/docs/#/) and this:
[http://swannodette.github.io/mori/](http://swannodette.github.io/mori/)

~~~
zatkin
Wow, this is wonderful input. I always love finding an overlap in terminology.
If you find the same description of something in more than two places, I think
it's safe to say that it's some kind of standard definition.

------
killtheliterate
I love this book for it's, ah, eloquent and inclusive way of describing more
advanced JS topics. Definitely of value, even for the more experienced JS dev.

------
osconfused
On the topic of functional JavaScript, a few interesting articles and books I
have been reading that have helped shed more light on this subject matter. I
particularly enjoyed the Functional JavaScript book [2].

[1] -
[http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf](http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdf)

[2] -
[http://shop.oreilly.com/product/0636920028857.do](http://shop.oreilly.com/product/0636920028857.do)

[3] - [http://stackoverflow.com/questions/36504/why-functional-
lang...](http://stackoverflow.com/questions/36504/why-functional-languages)

[4] -
[http://scott.sauyet.com/Javascript/Talk/2014/01/FuncProgTalk...](http://scott.sauyet.com/Javascript/Talk/2014/01/FuncProgTalk/#slide-0)

------
amelius
> The second relies on two external functions and is one line long.

> console.log(sum(range(1, 10)));

> Which one is more likely to contain a bug?

I'd say the second one. Because the first one is totally transparent. The
second one relies on functions I can't see. Especially the "range" function
may cause problems because here it generates the full range, including both
delimiters, unlike the range function in e.g. python.

EDIT: functional programming is extremely useful, but I don't think this
example really highlights the most important advantages.

~~~
netcraft
but sum and range are able to be tested in isolation and will be reused across
the application, making a bug in them more visible - rather than repeating the
logic of the loop in every instance where you need a loop. Also, when
maintaining the code later, the signal to noise ratio is much higher, you can
see exactly what is being attempted, not the implementation details of it.

There are certainly times when you need to see the implementation details or
that your needs don't fit the prescribed and available functions (eg, range
being exclusive vs inclusive), but then if that is the exception rather than
the rule, it will serve as another indicator when you come across that code
that `this is doing something different than usual`, so pay attention to the
details.

~~~
iopq
and then you forget range(1, 10) is a half-open interval because it's meant to
be used with `length` as in `range(0, foo.length)`

~~~
serrimo
That part has always annoyed me.

But then Python beat me into submission with its seductive collection
comprehension... Now I see it as a standard convention, like indexing should
start with 0.

------
VieElm
In ES6 there are iterables that one uses `for...of` with. Rauschmayer of
2ality has said that `for...of` should be used instead of forEach and I wonder
how that will affect composability in functional programming. I quite like the
concept of iteratables and creating data structures that can make use of for
of and generators. I just have thought about how that affects functional style
programming.

~~~
bzbarsky
for..of simply desugars into getting an iterator from the iterable and then
iterating it, right?

To compose iterables, you'd presumably work with iterators directly instead of
the sugar.

------
leeoniya
in case anyone missed it, it's by the author of CodeMirror [1], Acorn, Tern,
etc. [2]. He also contributes to Rust.

[1]
[https://github.com/codemirror/codemirror](https://github.com/codemirror/codemirror)

[2] [https://github.com/marijnh](https://github.com/marijnh)

------
romaniv
The theory is good, but the specifics of JS syntax, the type system, and the
lack of support from the standard library make functional programming much
less fun to use than in proper functional languages or even C#.

------
arcticf0x
great book!

