2017-12-22 8 views
-5

D:/work 폴더를 사용하여 스칼라 분할 방식으로 파일과 디렉토리의 수를 얻기 위해 노력하고있어,하지만 난 오류를 가진스칼라

import java.io._ 

val fd = (new File("D:/work/")).listFiles 

scala> fd.partition (x => {case x.isFile() => "FILE"; case x.isDirectory() => "DIR" }) 

<console>:28: error: missing parameter type for expanded function 
The argument types of an anonymous function must be fully known. (SLS 8.5) 
Expected type was: Boolean 
     fd.partition (x => {case x.isFile() => "FILE"; case x.isDirectory() => "DIR" }) 
         ^
<console>:28: error: method isFile is not a case class, nor does it have an unapply/unapplySeq member 
     fd.partition (x => {case x.isFile() => "FILE"; case x.isDirectory() => "DIR" }) 
          ^
<console>:28: error: method isDirectory is not a case class, nor does it have an unapply/unapplySeq member 
     fd.partition (x => {case x.isFile() => "FILE"; case x.isDirectory() => "DIR" }) 
                  ^

scala> 

답변

0

있습니다 많은 문제를 얻고을 사용하여 파일 및 디렉토리 수를 점점 당신의 코드는 스칼라 구문에 대한 책을 읽는 것으로 시작해야한다는 것을 나타냅니다. (이것이 왜 당신이 아래 표를 얻는 이유입니다).

이 시점에서 귀하의 스 니펫에 문제가있는 부분을 모두 열거하는 것은 의미가 없습니다. 이런 식으로 뭔가 당신이 원하는 것을 할 것입니다 :이 같은

val (files, directories) = fd.partition(_.isFile) 

또는 뭔가를 당신이 튜플보다는지도를 얻기 위해 찾고 있다면 :

val filesDirs = fd.groupBy { 
    case x if x.isFile => "FILE" 
    case _ => "DIR" 
    }