In functional programming, “folding” is something of a building block of other operations you may be familiar with, such as
Folding can be done from the left and from the right.
Choosing the best direction depends on the problem you’re solving.
TL;DR You can use Ruby destructuring and the splat operator (
simulate basic pattern matching.