本文介绍了Scala:curried构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下Scala类:
I have the following Scala class:
class Person(var name : String, var age : Int, var email : String)
我想使用Person构造函数作为curried函数:
I would like to use the Person constructor as a curried function:
def mkPerson = (n : String) => (a : Int) => (e : String) => new Person(n,a,e)
这种方法似乎有点乏味和容易出错。
This works, but is there another way to accomplish this? This approach seems a bit tedious and error-prone. I could imagine something like Function.curried, but then for constructors.
推荐答案
这将工作:
def mkPerson = (new Person(_, _, _)).curried
这篇关于Scala:curried构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!