如何在 scala curry 函数中绑定第二个参数?
How to bind second parameter in scala curry function?
//a curry function
def find(a: Seq[Int])(sort: (Int, Int) => Boolean)
//My attempt
val findWithBiggerSort = find(_)((a,b) => a > b)
findWithBiggerSort
无法运行,发生编译错误:
scala> def find(a: Seq[Int])(sort: (Int, Int) => Boolean)
| ={}
find: (a: Seq[Int])(sort: (Int, Int) => Boolean)Unit
scala> val findWithBiggerSort = find(_)((a,b) => a > b)
<console>:11: error: missing parameter type for expanded function ((x) => find(x)(((a, b) => a.$greater(b))))
val findWithBiggerSort = find(_)((a,b) => a > b)
^
如何绑定第二个 curry 参数?
如何将第二个参数绑定为 this
def find(a: Seq[Int], b: String)(sort: (Int, Int) => Boolean)
您有两个问题:
您的 sort
函数类型错误 - 您需要一个 (Int, Int) => Boolean
但您提供了一个 (Int, Int) => Int
。如果将其更改为:
val findWithBiggerSort = find(_)((a,b) => (a > b))
您收到 find (_)
中提供的 _
参数类型缺失的错误。如果您提供此类型,它会编译,即
val findWithBiggerSort = find(_:Seq[Int])((a,b) => (a > b))
或
val findWithBiggerSort = find(_:Seq[Int])(_ > _)
//a curry function
def find(a: Seq[Int])(sort: (Int, Int) => Boolean)
//My attempt
val findWithBiggerSort = find(_)((a,b) => a > b)
findWithBiggerSort
无法运行,发生编译错误:
scala> def find(a: Seq[Int])(sort: (Int, Int) => Boolean)
| ={}
find: (a: Seq[Int])(sort: (Int, Int) => Boolean)Unit
scala> val findWithBiggerSort = find(_)((a,b) => a > b)
<console>:11: error: missing parameter type for expanded function ((x) => find(x)(((a, b) => a.$greater(b))))
val findWithBiggerSort = find(_)((a,b) => a > b)
^
如何绑定第二个 curry 参数?
如何将第二个参数绑定为 this
def find(a: Seq[Int], b: String)(sort: (Int, Int) => Boolean)
您有两个问题:
您的 sort
函数类型错误 - 您需要一个 (Int, Int) => Boolean
但您提供了一个 (Int, Int) => Int
。如果将其更改为:
val findWithBiggerSort = find(_)((a,b) => (a > b))
您收到 find (_)
中提供的 _
参数类型缺失的错误。如果您提供此类型,它会编译,即
val findWithBiggerSort = find(_:Seq[Int])((a,b) => (a > b))
或
val findWithBiggerSort = find(_:Seq[Int])(_ > _)