scala Either & Neither handling -
Not sure what to call it, the option will only fit with either, to handle the third case the wanted.
Scalaz already provides something like this, but without a separate library, I'm curious to know, anyone can process the following simple case:
I have to see that a user session is present, as both the real users and administrators are taking pre-precedence as the log-in-in-user scenarios; If no condition exists, show the login screen.
Checks for the actual user session:
request.session.get (Security Username) Map {id = & gt; F (success (id.toInt, request))} getOrElse (onFail (request)) // onFail = show login and I must add the admin in the accused user case:
request.session.get (Security.impersonate) map {id = & gt; F. (success (id.toInt, request)}} getOrElse (onFail (request)) I can get all this at once, but would like to clear some things, operation Regardless of user or administrator-of-user cases.
not getOrElse, just orElse
scala & gt; Val Username: Option [String] = Any Username: Option [String] = Any Scale & gt; Val impersonate = some ("Fred") impersonation: some [java.lang.String] = some (Fred) scale & gt; UserName or Anselson Cloning res0: Option [String] = Some (Fred) Scale & gt; Val user name = some ("George") username: some [java.lang.String] = some (George) scale & gt; Username or Else Impresset Race 1: Option [Java.lang.string] = Some (George) Then in your case
session.get (Security) .username) or Elsie request.session.get (Security.impersonate) map {id = & gt; F (success (id.toInt, request))} getOrElse (onfell (request))
Comments
Post a Comment