柯里化
class MyCurry {
def curry(f: (Apple, Pear) => Peach): Pear => Peach = {
def c(pear: Pear): Peach = {
val apple = new Apple
f(apple, pear)
}
return c
}
}
class Apple
class Pear
class Peach
object Main extends App {
val myCurry = new MyCurry
val pear = new Pear
def f(apple: Apple, pear: Pear): Peach = new Peach
println(myCurry.curry(f)(pear))
}
网友评论