Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: curried constructors

Tags:

I have the following Scala class:

class Person(var name : String, var age : Int, var email : String) 

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.

like image 215
Chris Eidhof Avatar asked Oct 05 '10 10:10

Chris Eidhof


1 Answers

This will work:

def mkPerson = (new Person(_, _, _)).curried 
like image 178
Daniel C. Sobral Avatar answered Sep 30 '22 17:09

Daniel C. Sobral