Test Your Understanding!
-
Implement the lazy version of Enumerable#select.
Enumerable#select takes in a block containing a predicate. If the predicate evaluates to true, the element is emitted.
-
Implement the lazy version of Enumerable#drop.
drop takes in a single integer argument n. It drops the first n elements of the array and returns the rest. Note that since it is lazy, the rest of the enumerable still has to be constrained via first(n) or take(n).to_a.
Get Mastering Ruby Closures now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.