【发布时间】:2013-12-22 09:43:49
【问题描述】:
我有一个函数
def myInnerFunc(a: Int): Int = a
现在我想将它传递给一个高阶函数,并且我希望它传递给使用参数预初始化的高阶函数,因此需要首先使用正确的参数调用我的内部函数,然后我才能将它传递给高阶函数,组成如下:
def myHigherOrderFunction(func: Int => Int): Int = {
func()
}
所以我需要完成以下代码
myInnerFunc(1) // hmm fix this will actually call my innner function I just want to preinitialize it with one.
func() // didn't work for me how do i run my preinitialized with argument func Int => Int
- 如何在不运行的情况下使用参数 1 预初始化 myInnerFunc?
- 如何在高阶函数中运行 func()?
我不知道该怎么做,也找不到相关的文档,谁能提供一个例子? (我看到的所有例子都有多个参数,我只有一个)
【问题讨论】:
标签: scala functional-programming currying higher-order-functions