• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Scaladays 2011 - The Ease of Scalaz
 

Scaladays 2011 - The Ease of Scalaz

on

  • 3,957 views

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.

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.

Statistics

Views

Total Views
3,957
Views on SlideShare
3,943
Embed Views
14

Actions

Likes
5
Downloads
90
Comments
0

5 Embeds 14

http://a0.twimg.com 5
http://www.linkedin.com 3
https://twitter.com 3
http://paper.li 2
http://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Scaladays 2011 - The Ease of Scalaz Scaladays 2011 - The Ease of Scalaz Presentation Transcript

  • The Ease of Scalaz Scala Days 2011 Heiko Seeberger
  • Scala is object-functional
  • Scalaz is functional• Purely functional Scala library• Offering a wealth of useful type classes• Hosting: http://code.google.com/p/scalaz
  • Is Scalaz too complicated?
  • Don’t worryabout internal Just use itimplementation Is Scalaz too complicated?
  • 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
  • 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
  • We need a type-safe equals! Live demo
  • 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) }
  • 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 ?
  • 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!
  • Meet Validation Live demo
  • 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)
  • 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?
  • What we really want:def arg(index: Int): Validation[NonEmptyList[String], Int] = ...val result = { _ + _ } (arg(0), arg(1)) // Doesn’t compile!println(result)
  • 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!
  • Applicative programming Live demo
  • Thank you!Code: https://github.com/hseeberger/funEmail: heiko.seeberger(at)typesafe.com Twitter: hseeberger