scala:指定柯里化的方法类型

scala: Specifying method type for currying

以下方法类型描述了将配置信息和数据传递给方法的函数。这种类型的每个方法都可以执行不同的功能。

  type FTDataReductionProcess =(PipelineConfiguration,RDDLabeledPoint) => RDDLabeledPoint

以上作品完。

但我想做的是不同的。我想先将配置添加到方法中,然后再添加数据。所以我需要柯里化。

我认为这行得通:

  type FTDataReductionProcess =(PipelineConfiguration)(RDDLabeledPoint) => RDDLabeledPoint

但这会导致编译错误

Cannot resolve symbol RDDLabeledPoint

如有任何建议,我们将不胜感激

您想要一个接受 PipelineConfiguration 和 return 的函数,另一个接受 RDDLabeledPoint 和 return 和 RDDLabeledPoint 的函数。

  • 域名是什么? PipelineConfiguration.
  • 什么是return类型?一个"function that takes RDDLP and returns 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 = $$Lambda65/1442768482@54089484

scala> f(5)(7)  // applying curried function to two parameters
res0: Double = 0.7142857142857143