concept size in category scala

This is an excerpt from Manning's book Get Programming with Scala.
In the previous section, you have implemented a function, called stats, to perform statistics on a string (see listing 20.3). In particular, you have represented each of the predefined options with three functions called size, countLetters, countDigits. This solution works for a small set of alternatives, but it will quickly become particularly verbose once your program needs to provide more and more preferences: you will need to define a function with shape String => Int for each possible alternative. This approach can cause the number of functions in your program to explode: if you need to express 20 different alternatives, you will have 20 functions with a very similar structure. Another solution is to represent all the available selections with a set of well-defined values (or “union types”) and write a function to select the predicate filter to use for your stats function:
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.
scala> List(Foo(1, "zz"), Foo(9, "a"), Foo(8, "aa")).maxBy { foo => // ordering by the size of text // and then by its alphabetical order (foo.text.size, foo.text) ) res2: Foo = Foo(8, "aa")