class Country(code: String, name: String, population: Long) def find(n: String): ConnectionIO[Option[Country]] = sql"select code, name from country where name = $n”.query[Country].option find("France").transact(xa).unsafePerformIO Some(Country(FRA, France)) Doobie Sample
=> "yes" case 0 => "no" case _ => "error" } Traditional approach def get(animal: Animal): String = animal match { case cat: Cat => “I’m a cat: ” + cat.toString case dog: Dog => “I’m a dog: ” + dog.toString case _ => “Other animal" } Typed pattern
= dev match { case Developer(_, “scala”) => “Good Dev" case Developer(“Jorge Barroso”, _) => “The best" case _ => “Java Developers" } Cases Classes def developer(dev: Developer): String = dev match { case Developer(_, “scala”) => “Good Dev" case Developer(name, _) if name.contains(“Jorge”) => “The best" case _ => “Java Developers" } If statements