我试图在一个脚本中编写两个函数,但遇到了一个我无法解决的类型不匹配问题。以下是示例代码:
def generate(start: Int, end: Int): Seq[Int] = (start until end).toSeq
def restrain(seq: Seq[Int]) = seq.dropWhile(_ < 20).takeWhile(_ < 60)
val com: (Int, Int) => Seq[Int] = (restrain _ compose generate)通过将其加载到REPL中:
:load test.sc我得到以下错误:
val com: (Int, Int) => Seq[Int] = (restrain _ compose generate)
^
test.sc:1: error: type mismatch;
found : (Int, Int) => Seq[Int]
required: ? => Seq[Int]我做错了什么?
发布于 2020-06-19 18:33:31
Function2[Int, Int, Seq[Int]]和Function1[(Int, Int), Seq[Int]]类型不同。(generate _)生成前者,而对于此组合,您需要后者。尝试:
restrain _ compose (generate _).tupledhttps://stackoverflow.com/questions/62468237
复制相似问题