29 Working with List: properties
After reading this lesson, you will be able to:
- Inquiry over the size of a list
- Check if a sequence contains a specific item
- Count the number of elements that respect a given predicate
In the previous lesson, you have learned how to use the map and flatMap functions over an instance of List. These are two of its fundamental operations: when combined with a pattern matching statement, they allow you to implement the vast majority of function you can perform for a sequence. However, implementing over and over the same operations may not be practical, and at times not performant and challenging to maintain. For these reasons, the class List provides you with many ready-to-use and performant methods for many of its common transformations and queries. In this lesson, you are going to see which are the methods you can use to analyze some properties of a sequence. You are going to learn how to get the size of a list and check if it contains a given element. You are also going to investigate how many of its items respect a given predicate. In the capstone, you will use these operations to query and analyze the Movies Dataset.