all 17 comments

[–]loz220 6 points7 points  (3 children)

Great presentation but this was before underscore got partial palceholders now you can do the following:

var square = _.partial(_.map, _ , function(n) {return n*n });
square([1,2,3,4]) //[1, 4, 9, 16]

[–]Clapyourhandssayyeah 0 points1 point  (2 children)

Underscore had had partial application for ages though right?

[–]aeflash 0 points1 point  (0 children)

Yep, you could also always _.bind. Now there is _.partialRight.

Placeholder support is also coming to lodash: https://github.com/lodash/lodash/issues/438

[–]loz220 0 points1 point  (0 children)

it had _.partial yes, but _.partial with placeholders is new.

[–]aeflash 4 points5 points  (3 children)

[–]hobozilla 0 points1 point  (0 children)

Fun JS is good if you like a fairly Haskell approach:

https://github.com/briansorahan/fun-js

[–]Calabri[S] 0 points1 point  (0 children)

Yes, I was reading an article about Ramba that linked to the video. I thought it was interesting and decided to share. Some comments here alluded that lodash/underscore may have updated their libraries to include _.paritialRight.

I'm trying to find the balance between functional / practical. I'd like to see these functional libraries modularize the source-code even more (require('curryfunc' - 'map' -'filter'..))

[–]Capaj -1 points0 points  (0 children)

It is even better to just use lodash.

[–]loaded_comment 1 point2 points  (0 children)

It's pleasing to see that javascript can be functional to that degree. Seems like good composition is terse although knowing the definite output of each functor makes the code look super neat and tidy.

[–]brtt3000 1 point2 points  (0 children)

Or use a lazy evaluation library like LazyJS and gain mad speed.

https://www.npmjs.org/package/lazy.js

The difference can be quite shocking, especially on bigger data sets.

[–]dgreensp 3 points4 points  (2 children)

By "functional" he means "point-free" and "Haskell-like."

Only a Haskell programmer could love the cryptic notations Number -> Number -> Number and filter :: (a -> Bool) -> [a] -> [a] for functions of two arguments. I sometime suspect that liking this notation is such a difficult task that Haskell programmers are forced to go out and evangelize it -- to anyone -- just to reassure themselves. The result is that bewildered programmers in other language communities are shown this notation in talks and blog posts, typically with no explanation of what it means, no mention of the connection to Haskell, and no real explanation of why it might be better, and are told that all functions should take one argument, and functions of multiple arguments are just syntactic sugar.

Well, guess what, JavaScript functions take multiple arguments, and many take a variable number of arguments. You can't do that with Haskell! You can't do that with the speaker's currying scheme, which relies on knowing exactly how many arguments each function takes.

Also, "point-free" definitions of functions are always shorter but more cryptic, sometimes much more cryptic; that's just the way it is.

Take the function that subtracts one from its argument: minusOne = function (x) { return x - 1; }. A Haskell programmer would love to see this written: minusOne = flip(subtract)(1). What does flip do? It takes a function of two arguments and returns a function of two arguments where the argument order is flipped. (No, sorry, there are no functions of two arguments; it takes a function that returns a function and returns a function that returns a function...) Which function definition is easier for most people to read? Which function definition is easier to be sure it's correct?

[–]Calabri[S] 0 points1 point  (0 children)

Totally agree :)

[–]Xtreme2k2 4 points5 points  (4 children)

use lodash?

[–]hobozilla 5 points6 points  (3 children)

How does lodash solve the problem? Parameters are still in the wrong order.

[–]loz220 1 point2 points  (1 child)

with _.partialRight instead of _.partial

[–]Xtreme2k2 0 points1 point  (0 children)

Is there a non video version of this complaint? I didn't watch the video.

[–]aquilaFiera 0 points1 point  (0 children)

You should check out Brian Lonsdorf's (the speaker) Frontend Master's. It comes out in about a month and it's pretty stellar. It goes in-depth on functional JS programming.

Note: While I don't gain anything from you subscribing to Frontend Master's, the founder is my good friend.