Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Typeclasses, Monads, etc. - Functional programming in scala can be simple!

Typeclasses, Monads, etc. - Functional programming in scala can be simple!

I am quite excited how elegantly we can solve IO-bound problems like DB access with this new set of tools Scala and functional programming provides.
I've recently built a simple Cassandra client using actors, type classes and monads while migrating one of our systems at Zeebox from Amazon S3 to Cassandra.
It is simple and elegant (I believe :)) and it shows the real power of the language. So no more Java-like code written in Scala - It is functional but simple and powerful.

Until recently, I was scared myself whenever I've heard the phrase "type class" let alone monad or theory of categories. I realised that all it is, is just that mathematicians tend to overcomplicate things hiding it behind theorems and proofs. Real life examples of monoids, monads or type classes can be quite simple and understandable for everybody.

The video of this talk is available at:


Piotr Gabryanczyk

July 11, 2012

More Decks by Piotr Gabryanczyk

Other Decks in Technology


  1. Typeclasses, Monads, etc. Functional programming in Scala can be simple!

  2. Cassandra Client for Scala

  3. “The plan” • Typeclasses - code reuse • Actors -

    asynchronousness and self-healing • Monads - composition and reasoning
  4. • Keyspace =~ db schema • Column family =~ db

  5. Operations on rows

  6. Implicit keyspace

  7. Operations on objects

  8. Typeclasses Demo

  9. Typeclasses summary Numeric[T] Serializable[T]

  10. Actors

  11. JVM Cassandra Actor Router Actor Cassandra Actor Connection Cassandra Get(...)

    Cassandra Actor Connection Cassandra Actor Connection
  12. Blocking vs Non-blocking

  13. Akka Demo

  14. Actors API

  15. Composition

  16. Composition Demo

  17. Monads summary

  18. Questions? Peter Gabryanczyk @piotrga peter@scala-experts.com http://blog.scala4java.com We are hiring!