How to Use Lazy Loading in Ruby

0
2471

In this coding exercise we’ll examine how lazy loading can help us perform calculations on a large data collection.

Summary

Alter a method that maps over a large range of data so that it does not timeout.

Exercise File

Code File

Exercise Description

The following integer 1,000,000,000,000,000,000 crashes the method that attempts to map over it and calculate the square value of the first 5 elements. Update the method so that it can still take in the large number as an argument, but it only focuses on processing the first 5 elements. Also, you can’t simply shrink the value down to 5.

Real World Usage

Working with large data sets is important for many different applications, including web apps and machine learning algorithms. This exercise specifically focuses on understanding how enumerable methods work and the difference between eager and lazy loading.

Solution

Can be found on the solutions branch on github.

LEAVE A REPLY

Please enter your comment!
Please enter your name here