29 Working with List: Properties

 

After reading this lesson, you will be able to

  • Inquire 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 learned how to use the map and flatMap functions over an instance of List. These are two of its fundamental operations: when combined with pattern matching, they allow you to define the vast majority of operations you can perform for a sequence. However, implementing the same procedures over and over may not be performant and may be challenging to maintain. For these reasons, the class List provides you with many ready-to-use and performant functions for common transformations and queries. In this lesson, you’ll discover which methods you can use to analyze the properties of a sequence. You’ll learn how to get the size of a list and check if it contains a given element. You’ll also investigate how many of its items respect a given predicate. In the capstone, you will use these operations to query and analyze the movies data set.

29.1 Size of a list

29.2 Properties of the elements in a list

Summary

Answers to quick checks