2
저는 Scala에서 Beginning Scala을 통해 작업하는 초보자이며 예제가 작동하지 않는 것 같습니다. 여러 번 확인해 봤는데 코드가 어긋나는 부분을 찾을 수없는 것 같습니다.특성의 메서드에 대한 인수가 누락되었습니다. Iterator
sum.scala:18: error missing arguments for method collect in trait Iterator:
follow this method with '_' if you want to treat it as a partially applied function
val lines = input.getLines.collect
^
one error found
사람이 난 것에 도움이 되거 수 :
import scala.io._
def toInt(in: String): Option[Int] =
try {
Some(Integer.parseInt(in.trim))
} catch {
case e: NumberFormatException => None
}
def sum(in: Seq[String]) = {
val ints = in.flatMap(s => toInt(s))
ints.foldLeft(0)((a, b) => a + b)
}
println("Enter some numbers and press ctrl-D)")
val input = Source.fromInputStream(System.in)
val lines = input.getLines.collect
println("Sum "+sum(lines))
때마다 나는 다음과 같은 오류가 명령 Scala sum.scala
을 사용하여 실행하려고 : 나는 다음과 같은 스칼라 파일을 가지고 여기 잘못있는거야?
내가 .toList에 .collect을 변경하고 모든 것이 제대로 작동 - 주셔서 감사합니다 도움! – JoshC13