Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS: Collection Transformations #8

Open
JohnMurray opened this issue Jul 29, 2018 · 1 comment
Open

JS: Collection Transformations #8

JohnMurray opened this issue Jul 29, 2018 · 1 comment
Labels
new-code-example New code example

Comments

@JohnMurray
Copy link
Owner

JohnMurray commented Jul 29, 2018

This is kind of getting into the realm of functional programming but is very common in idiomatic JS. The example should compare built-in as well as library based collection transformations. This includes functions such as map, flatMap, filter, each, etc. Ideally over multiple collection types. Since JS mainly has lists ([]) and maps ({}), we should focus on those types. I think we should stay away from the newer types in JS such as Map as they 1) aren't much used in typical JS code and 2) do not provide functional interfaces.

For the JS library section, Lodash should be used as it is 1) the gold standard and highly popular JS library and 2) provides a wide variety of collection-based methods.

For the C++ library section, I think Boost will likely be what is used, but am open to other suggestions as long as the library can be considered extremely mainstream and heavily used by the community at large.

@JohnMurray JohnMurray added the new-code-example New code example label Jul 29, 2018
@semmel
Copy link
Contributor

semmel commented Jul 30, 2018

@JohnMurray Good idea to keep it general too by leaving out Map and Set.
However there is an abstraction Iterator Protocol available for all those Array Object, Map, Set. It would be interesting to compare it with STL-Iterators. Of course there is no STL <algorithm> in JS - for that - yet again - a FP utility library is needed.

Regarding Lodash, I don't think it serves Functional Programming in JS best.
I enjoyed watching Hey Underscore, You're Doing It Wrong! to learn why

function square(n) {
  return n * n;
} 
_.map([4, 8], square);
// => [16, 64]

is not so good as haveing that arguments swapped

var squareAll = map(square);
squareAll([4, 8]); // -> [16, 64]

(Lodash's API is that of Underscore.js.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-code-example New code example
Projects
None yet
Development

No branches or pull requests

2 participants