Hello, in this section, we'll learn about lists. Lists are a very commonly used data structure in Scala and that's useful to learn about in their own right. They also serve as an introduction to the collection classes, which is an extensive library of data structures that Scala provides. Before we go into the details of list, it will be helpful to have a bit of context. List is a part of Scala Standard Library. The Standard Library is code that's Scala comes with, you don't have to do anything special to use it in your projects. The goal of the Standard Library is to provide code that is generally useful in a wide range of projects. This means each project doesn't have to reinvent what is in the Standard Library, which saves time, and makes it easier for different projects to work together. Some examples of things in the Standard Library include, the collection classes which we are starting to learn about here, types and methods for error handling, mathematical functions like sine and cosine and classes for managing asynchronous computation. So, what are these collection classes we keep talking about? The idea is to provide different ways of storing data, where each particular way has some useful properties. For example, a Map allows us to look up data based on a key and a Stream can produce an infinite amount of data. This is a part of the collection classes and it's one of the simpler collections. The focus here is to get an overview of List. We'll see how this can be used to model collections of values, how to create List instances, and some of the basic operations we can perform on List. We're going to motivate the use of list by creating a simple address book. The address book has the following structure, Address book itself consists of zero or more contacts, and each contact has a name, an email address and then zero or more phone numbers. We can implement this structure using the code that is shown on the slide. We have an address book case class, and a contact case class. Within the address book, we represent the zero or more contacts using a list of contact. Within the contact case class, we have the name, which is a string, email, which is a string, and then the phone numbers, which we represent using a list of string, here using string to represent a phone number. This shows us one of the first and important properties of list. We can use it to represent zero or more of a particular type of item. Now, list has another property, which is very useful, which is that it maintains the order of the elements. We're not using that property here. The order of the contacts within the address book is not important, and neither is the order of the phone numbers within the contact. However, if we were interested in the order of elements, then list would also be a good choice to use. In the previous slide, we saw list types that had square brackets, such as, List[Contact], which we also have here. We haven't seen these kinds of types before, so we'll spend a little bit of time now to explain them. List types are parameterized by the type of the elements they hold, which is the type within the square brackets here. So, let me see, say, List[String], this is telling us that it's a list containing elements of type String. Similarly, for List[Contact], since contact is within the square brackets, that tells us we have a list containing elements of type contact. One of the implications of this is that, list can only hold elements of all the same type. This is different to say, JavaScript or Python, where you can put elements of different types into a collection. Here is a quick question to test your understanding of the types that we have just seen. What is the type of a list of list of numbers? Pause the video, until you've decided on your answer. If a list of numbers is a List[Int], then a list of list of numbers is a List[List[Int]], as shown on the slide. This is showing us that we can nest lists inside of lists, there's no arbitrary restriction here. Let's return to our address book example, and see how we can construct an instance of an address book, and hence how we can construct an instance of list, because an address book contains a list of contacts. Now, to create this list of contacts, we need to first create a contact, and a contact itself has a list of phone numbers. So, we're going to see our first example of constructing a list at the point where we construct a contact. That's what we do here, constructing alice who is a contact, and she has an empty list indicating she has no phone number. The second line here recreating another contact, this time is bob, he is a contact and he has a phone number. So, here we have an example of creating a list with one element, Bob's phone number. Now that we've created some contacts, we can go ahead and create the address book, which is what we do in this line here constructing the address book, and you can see we have a list containing Alice and Bob, our two contacts. So, we have an example here of constructing a list of two elements. So, there we have it, some examples of constructing lists, constructing an entry list, a list of one element, and a list of two elements. Now, that we've seen examples of constructing list with a given number of elements, let's generalize that to constructing list with an arbitrary number of elements. The generalization follows the same pattern we've seen already. If we have elements x1 through to xn that we wish to put into a list, we simply pass them to the list constructor as method parameters, that is values separated by commas and surrounded by parentheses. So, nothing special going on here, just application of the method course syntax we've already seen. Here are a few examples to drive the point home. Our first case we construct a list of strings containing three strings, apples, oranges, and pears. Our second example is a list of four numbers, 1, 2, 3 and 4. The third example is a list containing lists. This might represent diagonal matrix perhaps. The point here is that, putting lists inside lists is nothing special, is just the application of the same rule we've seen already. Finally we have the empty list. We've seen this one already, we passed no parameters here and just have the empty parentheses. We've seen how to construct list and our next stop on our tour of list is learning how to manipulate list. We're only going to see some of the really basic operations here and we're going to go into a lot more detail on collection classes in general, which also applies to list in sections that are still to come. Our first example here is getting the size of the list, which is the number of elements it contains. So, here we have our address book, we pull out the contacts list, and we call the size method on it. And the result of that is, 2, the number of elements it contains with Alice and Bob. Next thing we're going to do is look for a particular element which we do using, the contains method. Contains, has a parameter and the parameter is the element we're looking for here, we say we're looking for Alice and the result is true, indicating that the list does contain that element. The map method, allows us to transform a list, returning a new list which has the result of applying each element to a function. The function we're using here, which we pass as a parameter, takes the contact and returns just the name of that contact. So, when we call this whole thing on our list of contacts, we get the first names back, Alice and Bob, so a list containing Alice and Bob. Our final example here, is using filter. Now, the filter method takes a function, just like map. In this case, the function returns true for the elements we want to keep, and false otherwise. The function here in particular is looking for those elements that have a phone number, where the phone number is nonEmpty. So, that's going to just return the list containing Bob, because he is the only contact that has a phone number. You may remember, Alice has an empty list of phone numbers. So, there we have it, four example methods for manipulating list, size, contains, map, and filter, and we'll see plenty more of these to come in the future. And with that, we have concluded our quick introduction to list. So, let's quickly summarize what we've seen so far. Firstly, we learned that lists are useful when you want to model the case of containing zero or more of a particular type of element. We also learned that lists maintain the order of their elements, but that's not a property we used in the address book. We've seen how to construct lists, and we've also seen some of the basic operations for manipulating lists. We're going to go into a lot more detail on the operations that manipulate lists and other collection classes in some of the sections that are still to come.