Inject: Ruby's Fold

The Weekly Iteration

This video is only a short sample, but you can access the full version and all our other great content by subscribing.

Video

Notes

In this episode, Ben and Joe tackle a highly useful but lesser known method from Ruby's Enumerable module: inject.

While watching, you'll see how inject is just an abstraction over certain types of recursion. We'll use examples to demonstrate inject's many uses, including calculations on lists, implementing laziness for streaming large data sets, and building recursive data structures like Rack middleware chains.

You can read more about inject in the official documentation.

Ruby's inject is a Fold Function. You can read more about this concept on C2 Wiki or Wikipedia.

×

15 Full Courses, 100+ Screencasts & New Content Weekly