「Chapter 13 Iterators」の編集履歴(バックアップ)一覧はこちら
追加された行は緑色になります。
削除された行は赤色になります。
#co(){
Chapter 13 Iterators
Iterators are the imperative version of streams. Like streams, iterators describe potentially infinite lists. However, there is no data-structure which contains the elements of an iterator. Instead, iterators allow one to step through the sequence, using two abstract methods next and hasNext.
}
#setmenu2(ex-r-menu)
* 第 13 章 イテレータ (Iterators)
イテレータは、ストリームの命令型版です。ストリームのように、イテレータには無限リストを記述する能力があります。しかし、イテレータの成分を含むデータ構造はありません。代わりに、2つの抽象メソッド next と hasNext を使って、イテレータはシーケンスをたどることができます。
trait Iterator[+A] {
def hasNext: Boolean
def next: A
#co(){
Method next returns successive elements. Method hasNext indicates whether there are still more elements to be returned by next. Iterators also support some other methods, which are explained later.
}
メソッド next は、次の要素を返します。メソッド hasNext は next で返すべき要素がまだあるかどうかを示します。イテレータは他にもいくつかメソッドをサポートしていますが、それは後ほど説明します。
#co(){
As an example, here is an application which prints the squares of all numbers from 1 to 100.
}
例として、1 から 100 までの数の平方を表示してみます。
val it: Iterator[Int] = Iterator.range(1, 100)
while (it.hasNext) {
val x = it.next
println(x * x)
}
- [[13.1 Iterator Methods>Example13.1]]
- [[13.2 Constructing Iterators>Example13.2]]
- [[13.3 Using Iterators>Example13.3]]
#center(){[[前ページ>Chapter 12 Computing with Streams]] [[ 13 章>Chapter 13 Iterators]] [[目次>ScalaByExample和訳]] [[次ページ>Example13.1]]}
----
#comment
#co(){
Chapter 13 Iterators
Iterators are the imperative version of streams. Like streams, iterators describe potentially infinite lists. However, there is no data-structure which contains the elements of an iterator. Instead, iterators allow one to step through the sequence, using two abstract methods next and hasNext.
}
#setmenu2(ex-r-menu)
* 第 13 章 イテレータ (Iterators)
イテレータは、ストリームの命令型版です。ストリームのように、イテレータには無限リストを記述する能力があります。しかし、イテレータの成分を含むデータ構造はありません。代わりに、2つの抽象メソッド next と hasNext を使って、イテレータはシーケンスをたどることができます。
trait Iterator[+A] {
def hasNext: Boolean
def next: A
#co(){
Method next returns successive elements. Method hasNext indicates whether there are still more elements to be returned by next. Iterators also support some other methods, which are explained later.
}
メソッド next は、次の要素を返します。メソッド hasNext は next で返すべき要素がまだあるかどうかを示します。イテレータは他にもいくつかメソッドをサポートしていますが、それは後ほど説明します。
#co(){
As an example, here is an application which prints the squares of all numbers from 1 to 100.
}
例として、1 から 100 までの数の平方を表示してみます。
val it: Iterator[Int] = Iterator.range(1, 100)
while (it.hasNext) {
val x = it.next
println(x * x)
}
- [[13.1 イテレータメソッド >Example13.1]]
- [[13.2 イテレータの構築 >Example13.2]]
- [[13.3 イテレータの使用 >Example13.3]]
#center(){[[前ページ>Chapter 12 Computing with Streams]] [[ 13 章>Chapter 13 Iterators]] [[目次>ScalaByExample和訳]] [[次ページ>Example13.1]]}
----
#comment