Chunk Method

Learn how to split a collection into buckets of the same size.

How to split a collection into buckets

Let’s say we want to watch all of our favorite movies again. But on weekends, we only have time to watch three movies at most. Let’s decide which movies to watch. We need to split our movie catalog into buckets of three films, with one bucket of movies per weekend.

The Chunk method divides a collection into buckets, or chunks, of the same size. It receives the chunk size and returns a collection of collections.

Let’s find which movies to watch each weekend.

Get hands-on with 1000+ tech skills courses.