- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
How to make a partially applied ()=>a function from a multiple parameters function.
Sun, 2009-01-04, 09:39
Hi,
From a zero parameter function
def a = 1
I can create a partially applied function by using a _, which is of type ()=>Int.
Is it also possible to create a ()=>Int from function has parameters, like
def b(x:Int) = 1 + x
I want to create a ()=>a function from an existing multiple parameters function, but do not want to evaluate its value.
--
Cheers,
Keke
-----------------
We paranoid love life
From a zero parameter function
def a = 1
I can create a partially applied function by using a _, which is of type ()=>Int.
Is it also possible to create a ()=>Int from function has parameters, like
def b(x:Int) = 1 + x
I want to create a ()=>a function from an existing multiple parameters function, but do not want to evaluate its value.
--
Cheers,
Keke
-----------------
We paranoid love life
Sun, 2009-01-04, 10:17
#2
Re: How to make a partially applied ()=>a function from a multi
On Sun, Jan 4, 2009 at 12:38 AM, keke <iamkeke@gmail.com> wrote:
Hi,
From a zero parameter function
def a = 1
I can create a partially applied function by using a _, which is of type ()=>Int.
Is it also possible to create a ()=>Int from function has parameters, like
def b(x:Int) = 1 + x
scala> def b(x: Int) = x + 1b: (Int)Int
scala> val pab = () => b(42)pab: () => Int = <function>
scala> pab() res9: Int = 43
I want to create a ()=>a function from an existing multiple parameters function, but do not want to evaluate its value.
I can do it using this weird carried function syntax:
def c(x:Int)() = 1 + x
When using c(1) it gets evaluated and return 2, but when using c(1) _ it returns an function ()=>Int.
On Sun, Jan 4, 2009 at 4:38 PM, keke <iamkeke@gmail.com> wrote: