2012-03-20 5 views
1

args.foreach (arg => println (arg))를 보았습니다. 그러나 문서를 검색 할 때 http://www.scala-lang.org/api/current/index.html#scala.Array. 나는 그곳과 그것의 동반자 대상 문서를 찾지 못한다.스칼라 API 문서를 사용하는 방법?

어떤 조언이 필요합니까? 그래서이 방법이 배열에 사용할 수있는 볼 수있는 문서에 ArrayOps를 조회 할 수 있습니다 - 감사

+4

그런 경우에는 [scalex] (http://scalex.org/?q=Array+foreach)가 도움이 될 수 있습니다. – 4e6

+0

이것은이 사이트에서 내 첫 번째 Scala 질문이었습니다 ... http://stackoverflow.com/questions/6131309/scala-arrays-vs-vectors. 문서에는 실제로 미리 정의 된 implicits (또는 옵션 * 숨길 수있는 옵션)에서 사용할 수있는 모든 메서드를 표시하는 옵션이 필요합니다. scalex는 이것을하지 않으므로 이미'ArrayOps'에 함축되어 있다는 것을 알지 못한다면 도움이되지 않습니다 (이 경우에는 일반적인 API 문서를 볼 수 있습니다) –

답변

6

Arrayscala.collection.mutable.ArrayOps에서 foreach 같은 작업을 가져옵니다.

Predef에는 어레이에 사용할 수있는 다양한 암시 적 변환 방법이 포함되어 있습니다.

불행히도 Array에 대한 스칼라 API 설명서에서 Predef의 의미를 통해 이러한 메서드를 사용할 수 없다는 것을 알 수 없습니다.

1

Jesper가 말했듯이 암시 적 변환을 통해 얻은 방법에 대한 문서를 찾는 것이 쉽지 않습니다. 배열에 대해 정의 된 것과 그에 대한 이유는 here으로 설명됩니다.

암시 적 변환에서 비롯된 특정 방법의 출처를 찾는 일반적인 방법은 스칼라 REPL의 -print 옵션을 사용하는 것입니다.

당신이 scala -print를 실행하면 당신은 얻을 것이다 :

scala> Array(1,2,3,4) 
// ..... omitted for brevity 
res0: Array[Int] = Array(1, 2, 3, 4) 

scala> res0 foreach (println) 
[[syntax trees at end of cleanup]]// Scala source: <console> 
package $line2 { 
    final object $read extends java.lang.Object with ScalaObject { 
    def this(): object $line2.$read = { 
     $read.super.this(); 
    () 
    } 
    }; 
    @SerialVersionUID(0) final <synthetic> class $read$$iw$$iw$$anonfun$1 extends 
scala.runtime.AbstractFunction1 with Serializable { 
    final def apply(x: java.lang.Object): Unit = scala.this.Predef.println(x); 
    final <bridge> def apply(v1: java.lang.Object): java.lang.Object = { 
     $read$$iw$$iw$$anonfun$1.this.apply(v1); 
     scala.runtime.BoxedUnit.UNIT 
    }; 
    def this(): anonymous class $read$$iw$$iw$$anonfun$1 = { 
     $read$$iw$$iw$$anonfun$1.super.this(); 
    () 
    } 
    }; 
    final object $read$$iw$$iw extends java.lang.Object with ScalaObject { 
    private[this] val res1: scala.runtime.BoxedUnit = _; 
    <stable> <accessor> def res1(): Unit =(); 
    def this(): object $line2.$read$$iw$$iw = { 
     $read$$iw$$iw.super.this(); 
     $read$$iw$$iw.this.res1 = { 
     scala.this.Predef.intArrayOps($line1.$read$$iw$$iw.res0()).foreach({ 
      { 
      (new anonymous class $read$$iw$$iw$$anonfun$1(): Function1) 
      } 
     }); 
     scala.runtime.BoxedUnit.UNIT 
     }; 
    () 
    } 
    }; 
    final object $read$$iw extends java.lang.Object with ScalaObject { 
    def this(): object $line2.$read$$iw = { 
     $read$$iw.super.this(); 
    () 
    } 
    } 
} 

[[syntax trees at end of cleanup]]// Scala source: <console> 
package $line2 { 
    final object $eval extends java.lang.Object with ScalaObject { 
    @volatile protected var bitmap$0: Int = 0; 
    <stable> <accessor> lazy def $result(): Unit = { 
     if ($eval.this.bitmap$0.&(1).==(0)) 
     { 
      $eval.this.synchronized({ 
      if ($eval.this.bitmap$0.&(1).==(0)) 
       { 
       { 
        $eval.this.$print(); 
        $line2.$read$$iw$$iw.res1() 
       }; 
       $eval.this.bitmap$0 = $eval.this.bitmap$0.|(1); 
       () 
       }; 
      scala.runtime.BoxedUnit.UNIT 
      }); 
     () 
     }; 
    () 
    }; 
    private[this] val $print: java.lang.String = _; 
    <stable> <accessor> def $print(): java.lang.String = $eval.this.$print; 
    def this(): object $line2.$eval = { 
     $eval.super.this(); 
     $eval.this.$print = { 
     $line2.$read$$iw$$iw; 
     "" 
     }; 
    () 
    } 
    } 
} 

1 
2 
3 
4 

이 코드 내부 .foreach를 찾을 경우, 당신은이 방법이 실제로 intArrayOps에 호출을 알려줍니다 관련 라인을 찾아 볼 수 있습니다

scala.this.Predef.intArrayOps($line1.$read$$iw$$iw.res0()).foreach(
관련 문제