Function literal with multiple implicit arguments

后端 未结 4 1253
南笙
南笙 2020-12-20 15:43

How to define function literal with multiple implicit arguments in Scala? I\'ve tried this way:

def create = authAction { (implicit request, user) ⇒ // Synta         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-20 16:20

    There is no way to define an anonymous function with multiple implicit parameters.

    To elaborate on @pagoda_5b's answer and @paradigmatic's comment, section 6.23 of the Scala Language Specification defines anonymous functions like so:

    Expr ::= (Bindings | [‘implicit’] id | ‘_’) ‘=>’ Expr
    ResultExpr ::= (Bindings | ([‘implicit’] id | ‘_’) ‘:’ CompoundType) ‘=>’ Block
    Bindings ::= ‘(’ Binding {‘,’ Binding} ‘)’
    Binding ::= (id | ‘_’) [‘:’ Type]
    

    As you can see, you can either define a list of parameters or a single implicit parameter.

    If you need multiple parameters to be implicit, you need to curry them.

提交回复
热议问题