Skip to content

Instantly share code, notes, and snippets.

@rahilb
Last active December 8, 2015 09:57
Show Gist options
  • Save rahilb/9880c932a6b7075c03c0 to your computer and use it in GitHub Desktop.
Save rahilb/9880c932a6b7075c03c0 to your computer and use it in GitHub Desktop.
Scalaz solutions for scala warts
import scalaz._
import Scalaz._
// Option#getOrElse is ugly
val two = None | 2
// if else & bool match are ugly
val three = true.fold(t = 3, f = 0)
// nested method calls can become ugly & hard to read
scala> def dub(i: Int) = i * 2
scala> def trip(i: Int) = i * 3
// ugly!
scala> trip(trip(dub(1)))
res2: Int = 18
// awesome!
scala> 1 |> dub |> trip |> trip
res3: Int = 18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment