以下方法类型描述了将配置信息和数据传递给方法的函数。这种类型的每种方法都可以执行不同的功能。
type FTDataReductionProcess =(PipelineConfiguration,RDDLabeledPoint) => RDDLabeledPoint
以上工作完成。
但我想做的是不同的。我想先将配置添加到方法中,然后再添加数据。所以我需要柯里化(Currying)。
我认为这会起作用:
type FTDataReductionProcess =(PipelineConfiguration)(RDDLabeledPoint) => RDDLabeledPoint
但这会导致编译错误
Cannot resolve symbol RDDLabeledPoint
如有任何建议,我们将不胜感激
最佳答案
您需要一个接受PipelineConfiguration
并返回另一个接受RDDLabeledPoint
并返回RDDLabeledPoint
的函数。
- 域名是什么?
管道配置
。 - 返回类型是什么?一个“接受
RDDLP
并返回RDDLP
的函数”,即:(RDDLabeledPoint => RDDLabeledPoint)
。
一起:
type FTDataReductionProcess =
(PipelineConfiguration => (RDDLabeledPoint => RDDLabeledPoint))
由于 =>
是右关联的,因此您还可以编写:
type FTDataReductionProcess =
PipelineConfiguration => RDDLabeledPoint => RDDLabeledPoint
顺便说一下:函数文字也同样适用,它提供了一个很好的简洁语法。这是一个较短的示例来演示这一点:
scala> type Foo = Int => Int => Double // curried function type
defined type alias Foo
scala> val f: Foo = x => y => x.toDouble / y // function literal
f: Foo = $$Lambda$1065/1442768482@54089484
scala> f(5)(7) // applying curried function to two parameters
res0: Double = 0.7142857142857143
关于scala:指定柯里化(Currying)的方法类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48481614/