Skip to content

Instantly share code, notes, and snippets.

@ktoso
Last active December 14, 2015 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktoso/5012875 to your computer and use it in GitHub Desktop.
Save ktoso/5012875 to your computer and use it in GitHub Desktop.
Example on why one should bother to learn monads/scalaz => it really cleans up real life code :-)
import scalaz._
val failOrBusiness: Validation[Error, Business] = for {
business <- doBusiness()
_ <- validateBusiness(business) // we can inspect the business here, it's like "case Right(business) =>"
} yield business
// instead of Either, use monadic Validation
val iFeelLikeIt: Boolean = ???
def doBusiness(): Validation[Error, Business] =
if (iFeelLikeIt)
Business().success
else
Error("No business :<").fail
def validateBusiness: Validation[Error, Unit] = ???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment