What Can Array Folding Do?

Neil Syiemlieh on April 20, 2019

This is Part 2 of the "Folds" series, where we look at how we could use the simple Fold pattern to perform a variety of array processing tasks. ... [Read Full]
markdown guide

Thanks Neil for your interesting article.

Sounds as if you may be interested in Ian Hofmann-Hicks youtube channel (search evilsoft on youtube) and his Crocks A.D.T library github.com/evilsoft/crocks

But, of course, you may have encountered his offerings before.


Thanks! I had never heard of him but his content is exactly the kind of stuff I'm interested in. Reminds me of the Fantasy land spec I recently found


I will look forward to further articles from you soon, I hope.


What's the benefit of doing this instead of just using the built in Array.prototype.reduce?


There is not benefit other than exploring it for fun!


I don't understand the pipe one, can you explain it better, or at least say examples of usage?



The pipe takes in an array of functions and "connects" them so that the output of a function within that array is passed as an input to the function after it.

const squareThenIncrement = pipe([x => x * x, x => x + 1])
squareThenIncrement(4);  // 17
squareThenIncrement(9);  // 82

There are a few medium articles out there explaining it in more detail. I didn't want to make this post too detailed. I just wanted to show how much we could do using just that fold function


Dude. Please stop reinventing the wheel and do start reading the proper documentations.

Your "fold" is not a thing.

You are basically renaming and trying to hijack the credits from Array.prototype.reduce

And in case you didn't know it, the Array object also exposes methods like some(), every() that you called all(), join() etc.


You seem very well-versed in JS array methods. You're right, these functions are already available in the standard API. But why does that have to stop anyone from experimenting for the sake of learning? Relax


You are right, this is a very nice exercise to train.

Sloan, the sloth mascot Comment marked as low quality/non-constructive by the community View code of conduct

Arrays folding can't be that complicated!!! Niel I think U should check yourself!!! Just too much stuff crammed together with out logistics logical reason. Just too much stuff running together and not really making much sense. It's kinda like U never learned any one thing. Sorry if I'm wrong. If wrong I apologized. If right there needs to be a fix. Smallest things together in one little group. Stick with one CPL. C#, Rust, Haskell, Python, html,css, JavaScript,One Computer Programming Language!!! Wiltel49@gmail.com


Array folding should never be this complicated, this was all just me experimenting with the idea. This post (along with most of my other posts) is just a way for me to solidify concepts that I recently learned while also having a way to improve my writing. So I might end up straying in my posts sometimes but that's kinda what makes it fun for me.


Great post and it was very interesting to see the depth you added in the code. Too often people just grab a higher order or a library to do the work without giving it a go to check fundamentals or a new approach. We would never innovate without this curiosity and I applaud your hard work on this and an excellent formed post 👍

Sloan, the sloth mascot Comment marked as low quality/non-constructive by the community View code of conduct

What are you talking about? Instead of rambling, come up with an improvement, cause it sounds like you're just full of shit.

code of conduct - report abuse