Scala: curried constructors

☆樱花仙子☆ 提交于 2019-11-29 05:32:07

This will work:

def mkPerson = (new Person(_, _, _)).curried

A bit late to this party, but if you make Person a case class:

scala> case class Person(name: String, age: Int, email: String)
defined class Person

Scala generates a companion object containing Person.apply(String, Int, String) and some other stuff for you. Then you can do:

scala> Person.curried
res5: String => (Int => (String => Person)) = <function1>

Which is shorthand for:

(Person.apply _).curried

It works with var parameters too.

may be so:

val mkPerson = Function.curried((n: String,a:Int,e:String) => new Person (n,a,e))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!