scala> val a: Int = 5
                a: Int = 5
              
              
                scala> val a = 5
                a: Int = 5
              
              
                scala> def add(x:Int, y:Int) = x + y
                # add: (x: Int, y: Int) => Int

                scala> add(5, 3)
                res0: Int = 8
              
            
              
                class User {
                    private String name;

                    private List orders;

                    public User() { orders = new ArrayList(); }

                    public String getName() { return name; }

                    public void setName(String name) { this.name = name; }

                    public List getOrders() { return orders; }

                    public void setOrders(List orders) { this.orders = orders; }
                }

                public class Order {
                    private int id;

                    private List products;

                    public Order() { products = new ArrayList(); }

                    public int getId() { return id; }

                    public void setId(int id) { this.id = id; }

                    public List getProducts() { return products; }

                    public void setProducts(List products) { this.products = products; }
                }

                public class Product {
                    private int id;

                    private String category;

                    public int getId() { return id; }

                    public void setId(int id) { this.id = id; }

                    public String getCategory() { return category; }

                    public void setCategory(String category) { this.category = category; }
                }
                
            
              
                case class User(name: String, orders: Seq[Order])
                case class Order(id: Int, products: Seq[Product])
                case class Product(id: Int, category: String)
                
                val product = Product(1, "Fidget spinner")
                val order = Order(1, Seq(product))
                val user = User("Magnus", Seq(order))
                # user: User = User(Magnus, List(
                               Order(1, List(
                               Product(1,Fidget spinner)))))
                
            
            
              
                case class User(firstName: String, surname: String)

                val user = new User("Scala", "IO")
                # user: User = User(Scala,IO)

                val user = User.apply("Scala", "IO")
                # user: User = User(Scala,IO)

                val user = User("Scala", "IO")
                # user: User = User(Scala,IO)

                val user2 = user.copy(firstName = "Magnus")
                # user2: User = User(Magnus,IO)
              
            
              
                case class User(firstName: String, surname: Option[String])

                def matchUser(u: User) =
                  u match {
                    case User(fname, None) => 
                      println(s"Got first name: $fname but no surname"))
                    case User(_, Some(lName)) => 
                      println(s"Got lastname: $lName and ignored first name")
                  }
              
            
              
                trait Person
                case class Customer(vip: Boolean) extends Person
                case class Employee(jobTitle: String) extends Person
                case object Nerd extends Person
                case object User extends Person

                def matchUser(p: Person) = p match {
                  case Customer(true) => println("Customer is VIP"))
                  case Customer(false) => println("Customer is not VIP"))
                  case Nerd => println(s"Great, we got a nerd!")
                  case _ => println("all other cases")
                }
              
            
Partial functions
              
              Seq(1, "ScalaIO").map {
                case i: Int => i 
                case s: String => s
              }
              # Seq[Any] = List(1, ScalaIO)

              Seq(1, "ScalaIO", true).map {
                case i: Int => i.toString 
                case s: String => s
              }
              # scala.MatchError: true (of class java.lang.Boolean)

              Seq(1, "ScalaIO", true).collect {
                case i: Int => i.toString 
                case s: String => s
              }
              # Seq[String] = List(1, ScalaIO)
              
            
             
               users.flatMap(u => u.orders.flatMap(o => o.products))
               # Seq[Product]

               for {
                 user <- users
                 orders <- user.orders
                 products <- orders.products
                 } yield products
                 # Seq[Product]