Scaladays 2011 - The Ease of Scalaz

4,179 views
4,097 views

Published on

Slides of my talk "The Ease of Scalaz" at the Scala Days 2011 conference in Stanford, CA. The talk included a significant amount of live coding, hence the slides alone are of little avail.

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,179
On SlideShare
0
From Embeds
0
Number of Embeds
31
Actions
Shares
0
Downloads
92
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Scaladays 2011 - The Ease of Scalaz

    1. 1. The Ease of Scalaz Scala Days 2011 Heiko Seeberger
    2. 2. Scala is object-functional
    3. 3. Scalaz is functional• Purely functional Scala library• Offering a wealth of useful type classes• Hosting: http://code.google.com/p/scalaz
    4. 4. Is Scalaz too complicated?
    5. 5. Don’t worryabout internal Just use itimplementation Is Scalaz too complicated?
    6. 6. What’s wrong with this code? val versionToYear = Map( "1.0" -> "2003", "2.0" -> "2006", "2.9" -> "2011") def isVersionFromYear(version: String, year: String) = (versionToYear get version) == year
    7. 7. What’s wrong with this code? val versionToYear = Map( "1.0" -> "2003", "2.0" -> "2006", "2.9" -> "2011") def isVersionFromYear(version: String, year: String) = (versionToYear get version) == year == is not type-safeHence isVersionFromYear will always return false
    8. 8. We need a type-safe equals! Live demo
    9. 9. How should we handle effects? def effects(args: String *): Unit = { def arg(index: Int) = args(index).toInt val result = arg(0) + arg(1) println(result) }
    10. 10. How should we handle effects? def effects(args: String *): Unit = { def arg(index: Int) = args(index).toInt val result = arg(0) + arg(1) println(result) } Option, Either ?
    11. 11. How should we handle effects? def effects(args: String *): Unit = { def arg(index: Int) = args(index).toInt val result = arg(0) + arg(1) println(result) } Option, Either ? Validation!
    12. 12. Meet Validation Live demo
    13. 13. How can we process effects?def arg(index: Int): Validation[NonEmptyList[String], Int] = ...val result = (arg(0), arg(1)) match { case (Success(i0), Success(i1)) => Success(i0 + i1) case (Failure(f0), Failure(f1)) => Failure(f0.list <::: f1) case (f @ Failure(_), _) => f case (_, f @ Failure(_)) => f}println(result)
    14. 14. How can we process effects?def arg(index: Int): Validation[NonEmptyList[String], Int] = ...val result = (arg(0), arg(1)) match { case (Success(i0), Success(i1)) => Success(i0 + i1) case (Failure(f0), Failure(f1)) => Failure(f0.list <::: f1) case (f @ Failure(_), _) => f case (_, f @ Failure(_)) => f}println(result) Not very helpful, right?
    15. 15. What we really want:def arg(index: Int): Validation[NonEmptyList[String], Int] = ...val result = { _ + _ } (arg(0), arg(1)) // Doesn’t compile!println(result)
    16. 16. What we really want:def arg(index: Int): Validation[NonEmptyList[String], Int] = ...val result = { _ + _ } (arg(0), arg(1)) // Doesn’t compile!println(result) We want to apply a pure function to effectful arguments!
    17. 17. Applicative programming Live demo
    18. 18. Thank you!Code: https://github.com/hseeberger/funEmail: heiko.seeberger(at)typesafe.com Twitter: hseeberger

    ×