extends ChatProtocol case class Join(userId:Int, name:String) extends ChatProtocol case class Leave(userId:Int) extends ChatProtocol command match { case Message(id, text) => println(s"${users(id)}: ${text}") case Join(id, name) => { users += (id, name) println(s"${name} joined") } case Leave(id) => { println(s"${users(id)} left") users -= id } }
Data transformation pipeline instead of CRUD • “Sane” error handling, data validation http://fsharpforfunandprofit.com/rop/ • Computation and data composition For comprehensions (Monads …)
strategy new Order to buy(200 sharesOf "GOOGLE") maxUnitPrice 300 using defaultPricing, // use a custom pricing strategy new Order to sell(200 bondsOf "Sun") maxUnitPrice 300 using { (qty, unit) => qty * unit - 500 } ) http://debasishg.blogspot.com/2008/05/designing-internal- dsls-in-scala.html
This is a specification for the 'Hello world' string The 'Hello world' string should contain 11 characters $e1 start with 'Hello' $e2 end with 'world' $e3 """ def e1 = "Hello world" must haveSize(11) def e2 = "Hello world" must startWith("Hello") def e3 = "Hello world" must endWith("world") } https://etorreborre.github.io/specs2/
the Impatient http://www.horstmann.com/scala/ • Programming in Scala http://www.artima.com/shop/programming_in_scala_2ed • Functional Programming in Scala http://manning.com/bjarnason/