Skip to content

fix Range examples. remove Range.ByOne #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,14 @@ first in first out) だ。
範囲 ([`Range`](http://www.scala-lang.org/api/{{ site.scala-version }}/scala/collection/immutable/Range.html)) は順序付けされた等間隔の整数の列だ。例えば、「1、2、3」は範囲であり、「5、8、11、14」も範囲だ。Scala で範囲を作成するには、予め定義された `to` メソッドと `by` メソッドを使う。

scala> 1 to 3
res2: scala.collection.immutable.Range.Inclusive
with scala.collection.immutable.Range.ByOne = Range(1, 2, 3)
res2: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3)
scala> 5 to 14 by 3
res3: scala.collection.immutable.Range = Range(5, 8, 11, 14)

上限を含まない範囲を作成したい場合は、`to` の代わりに、便宜上用意された `until` メソッドを使う:

scala> 1 until 3
res2: scala.collection.immutable.Range.Inclusive
with scala.collection.immutable.Range.ByOne = Range(1, 2)
res2: scala.collection.immutable.Range = Range(1, 2)

範囲は、開始値、終了値、ステップ値という、たった三つの数で定義できため定数空間で表すことができる。そのため、範囲の多くの演算は非常に高速だ。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,14 @@ Note that `dequeue` returns a pair consisting of the element removed and the res
A [Range](http://www.scala-lang.org/api/{{ site.scala-version }}/scala/collection/immutable/Range.html) is an ordered sequence of integers that are equally spaced apart. For example, "1, 2, 3," is a range, as is "5, 8, 11, 14." To create a range in Scala, use the predefined methods `to` and `by`.

scala> 1 to 3
res2: scala.collection.immutable.Range.Inclusive
with scala.collection.immutable.Range.ByOne = Range(1, 2, 3)
res2: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3)
scala> 5 to 14 by 3
res3: scala.collection.immutable.Range = Range(5, 8, 11, 14)

If you want to create a range that is exclusive of its upper limit, then use the convenience method `until` instead of `to`:

scala> 1 until 3
res2: scala.collection.immutable.Range.Inclusive
with scala.collection.immutable.Range.ByOne = Range(1, 2)
res2: scala.collection.immutable.Range = Range(1, 2)

Ranges are represented in constant space, because they can be defined by just three numbers: their start, their end, and the stepping value. Because of this representation, most operations on ranges are extremely fast.

Expand Down
1 change: 0 additions & 1 deletion tutorials/FAQ/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ it. Also available are some traits with further refinements, such as

* `immutable.Range` -- A delimited sequence of integers, closed on the lower end, open on the high end, and with a step.
* `immutable.Range.Inclusive` -- A `Range` closed on the high end as well.
* `immutable.Range.ByOne` -- A `Range` whose step is 1.
* `immutable.NumericRange` -- A more generic version of `Range` which works with any `Integral`.
* `immutable.NumericRange.Inclusive`, `immutable.NumericRange.Exclusive`.
* `immutable.WrappedString`, `immutable.RichString` -- Wrappers which enables seeing a `String` as a `Seq[Char]`, while still preserving the `String` methods. I'm not sure what the difference between them is.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,14 @@ Vector结构通常被表示成具有高分支因子的树(树或者图的分
[Range]表示的是一个有序的等差整数数列。比如说,“1,2,3,”就是一个Range,“5,8,11,14,”也是。在Scala中创建一个Range类,需要用到两个预定义的方法to和by。

scala> 1 to 3
res2: scala.collection.immutable.Range.Inclusive
with scala.collection.immutable.Range.ByOne = Range(1, 2, 3)
res2: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3)
scala> 5 to 14 by 3
res3: scala.collection.immutable.Range = Range(5, 8, 11, 14)

如果您想创建一个不包含范围上限的Range类,那么用until方法代替to更为方便:

scala> 1 until 3
res2: scala.collection.immutable.Range.Inclusive
with scala.collection.immutable.Range.ByOne = Range(1, 2)
res2: scala.collection.immutable.Range = Range(1, 2)

Range类的空间复杂度是恒定的,因为只需要三个数字就可以定义一个Range类:起始、结束和步长值。也正是因为有这样的特性,对Range类多数操作都非常非常的快。

Expand Down