I'd like to be able to pass in a function to a class such that the function always returns a Boolean, but the number of arguments can be variable.
This is actually what I'm working with right now:
/**
* Template class for any SecureSocial SecuredAction.
*/
class SomeAction[T](
isSuccessful: (SecuredRequest[AnyContent], T) => Boolean,
success: Result,
failure: Result) extends SecureSocial {
def toReturn = SecuredAction(WithProvider("google")) {
implicit request => if (isSuccessful(request)) success else failure
}
}
I'd like the isSuccessful
argument to be a function that takes at least one argument of type SecuredRequest[AnyContent]
and a zero or more arguments after that. Sometimes I'll pass in a function that only needs the request
object, and sometimes I'll pass in a function that needs the request
object and some other parameters.
After seeing this answer I looked at currying, which is the practice of transforming a multiple-argument function into a single-argument function that will return a function if any more arguments are needed. This sounds like it can solve my problem, but after reading up on the difference between partially applied functions and currying, I'm starting to think not? It looks like there is still a set number of eventual arguments...
I suppose successful currying would go like so:
class SomeAction[T](
isSuccessful : ((SecuredRequest[AnyContent])(T) => Boolean) , // ERROR
... ) ... { ... }
This definitely isn't the right syntax.
or
class SomeAction[T](
isSuccessful : (SecuredRequest[AnyContent] => Boolean) ,
... ) ... { ... }
with something done to isSuccessful
in toReturn
to uncurry the passed function.
Multiple questions that may lead me to the answer:
- Is there some particular syntax for describing curried functions I don't know about?
- Or I'd have a type
(SecuredRequest[AnyContent] => Boolean)
function, but do some sort of uncurrying on theisSuccessful(request)
call?
Thanks for reading; I guess I'm just looking for uncurrying examples.