Dan Wilson
1 min readSep 19, 2017

--

I appreciate the focus on fundamentals. I brought up the usage of zip because I think it is a fundamental as much as map, filter, and reduce are. I also think without it your example undersells functional programming as a simplifying factor. More importantly, it doesn’t seem to illustrate the difference between the functional and imperative mindset to me. In my experience that difference seems to be a focus on what over how, and a focus on explicitly specified and minimized data dependencies. In your example you start with three lists. What do you want to do? Combine them into a single list. I think if you don’t want to introduce zip, then more than map, a recursive function is the best way to implement this.

function artistsCorrect(artistsList, photosList, camerasList) {
const [artist, ...artists] = artistList;
const [photo, ...photos] = photosList;
const [camera, ...cameras] = camerasList;

if(artist && photo && camera) {
return [{
...artist, photo, camera
}].concat(artistsCorrect(artists, photos, cameras));
}

return [];
}

It makes use of some more advanced ES6 features, but I think that’s okay. My only hesitation against recursion is that it is sort of the “goto” of functional programming. It’s very powerful but easy to go crazy and make things worse. One thing I prefer about the recursive solution is you don’t need to explicitly depend on the index of the iteration like you did with the map based solution. You do, however, need to specify a base case.

--

--