From the course: Scala Essential Training for Data Science

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Filtering parallel collections

Filtering parallel collections - Scala Tutorial

From the course: Scala Essential Training for Data Science

Start my 1-month free trial

Filtering parallel collections

- [Instructor] Sometimes, when we have large collections we want to filter them. Scala makes it easy to filter collections so you can find all the members of a collection that meet some criteria. So for example, let's create an array of numbers. We'll create val v. And we'll make this one to 10,000. And let's make it an array. And let's create a parallel version by using the par method. Now let's just check the length of the collections. V.lengths and pv.length. OK, they're the same. Numbers appear to be the same. So we'll just clear the screen, and we'll move on to our next step. So we have a collection of 10,000 elements. What I'd like to do now is create another value that has the elements from pv, the parallel vector, that are greater than 5,000. So I'm going to make a new value, and I'll call it pvf for the filtered version of pv. And I'm going to define that as pv.filter. So I'll apply a filter. So for each element of the collection, I want to do a test and see if it is greater…

Contents