Created
June 15, 2013 17:58
-
-
Save jessitron/5788968 to your computer and use it in GitHub Desktop.
This is in response to a giant twitter thread.
Thanks to @CraigBuchek, @brianbuttonxp, @adkron, @heathborders, and @marioaquino for the discussion. Post is at blog.jessitron.com, titled "What's dirtier than comments? Exceptions!"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Error(message:String) | |
case class AuthLevel(value: Int) | |
object AuthLevel { | |
val GUEST = AuthLevel(0) | |
} | |
class SettingGetter { | |
def get_setting(settingName: String): Either[Error, String] = Right("Fred") | |
} | |
class Authorizer { | |
def getAuthorizationLevel(user: String): AuthLevel = AuthLevel(4) | |
} | |
class ForBlogPost { | |
def getAuthLevel(c : SettingGetter, | |
authorizer: Authorizer): Either[Error, AuthLevel] = { | |
val possibleUser = c.get_setting("username") | |
val possibleAuth = possibleUser.right.map{ user => | |
authorizer.getAuthorizationLevel(user) } | |
possibleAuth.joinRight | |
} | |
def doSomethingWithAuthLevel() { | |
val possibleAuth = getAuthLevel(new SettingGetter, new Authorizer) | |
possibleAuth.left.foreach(error => log(error)) | |
val authLevel: AuthLevel = possibleAuth.right.getOrElse(AuthLevel.GUEST) | |
} | |
def log(a: Any) { println(a) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment