This repository was archived by the owner on Mar 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcollections_18.html
More file actions
98 lines (98 loc) · 4.62 KB
/
collections_18.html
File metadata and controls
98 lines (98 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 25 March 2009), see www.w3.org" />
<title>Scala 2.8 コレクション API -- 範囲</title>
<link rel="stylesheet" type="text/css" href="guide.css" />
</head>
<body dir="ltr">
<table width="100%" cellpadding="0" cellspacing="2">
<tr>
<td bgcolor="#99CCFF"><a href="collections_19.html"><img border="0"
alt="ハッシュトライ" src="next.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_12.html"><img border="0"
alt="具象不変コレクションクラス" src="up.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_17.html"><img border="0"
alt="不変キュー" src="previous.png" /></a></td>
<td align="center" bgcolor="#99CCFF" width="100%"><b>範囲</b></td>
<td bgcolor="#99CCFF" align="center" class="tocref"><a href=
"collections_49.html">目次</a></td>
</tr>
</table>
<blockquote style=
"border-left: 1px solid gray; font-family: Century, Times, 'Times New Roman', 'MS Gothic', serif; padding-left: 1em;">
最新版は <a href="http://docs.scala-lang.org/ja/overviews/collections/concrete-immutable-collection-classes.html">Scala Documentation</a> に移行しました。
</blockquote>
<h2>範囲</h2>
<p>範囲 (<a href=
"http://www.scala-lang.org/api/current/scala/collection/immutable/Range.html"><tt>Range</tt></a>)
は順序付けされた等間隔の整数の列だ。例えば、「1, 2, 3」は範囲であり、「5, 8, 11, 14」も範囲だ。Scala
で範囲を作成するには、予め定義された <tt>to</tt> メソッドと <tt>by</tt> メソッドを使う。</p>
<div class="quote">
<table cellspacing="1" cellpadding="0">
<tr>
<td colspan="99" align="left"><tt>scala> <font color=
"#000000">1</font> to <font color=
"#000000">3</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">res2: scala.collection.immutable.</font></tt><tt><font color="#590000">Range.</font></tt><tt><font color="#590000">Inclusive</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000"> with scala.collection.immutable.</font></tt><tt><font color="#590000">Range.</font></tt><tt><font color="#590000">ByOne = Range(1, 2, 3)</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt>scala> <font color=
"#000000">5</font> to <font color=
"#000000">14</font> by <font color=
"#000000">3</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">res3: scala.collection.immutable.</font></tt><tt><font color="#590000">Range = Range(5, 8, 11, 14)</font></tt></td>
</tr>
</table>
</div>
<p>上限を含まない範囲を作成したい場合は、<tt>to</tt> の代わりに、便宜上用意された <tt>until</tt>
メソッドを使う:</p>
<div class="quote">
<table cellspacing="1" cellpadding="0">
<tr>
<td colspan="99" align="left"><tt>scala> <font color=
"#000000">1</font> until <font color=
"#000000">3</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000">res2: scala.collection.immutable.</font></tt><tt><font color="#590000">Range.</font></tt><tt><font color="#590000">Inclusive</font></tt></td>
</tr>
<tr>
<td colspan="99" align="left"><tt><font color=
"#590000"> with scala.collection.immutable.</font></tt><tt><font color="#590000">Range.</font></tt><tt><font color="#590000">ByOne = Range(1, 2)</font></tt></td>
</tr>
</table>
</div>
<p>
範囲は、開始値、終了値、ステップ値という、たった三つの数で定義できため定数空間で表すことができる。そのため、範囲の多くの演算は非常に高速だ。</p>
<p>続いては、<a href="collections_19.html">ハッシュトライ</a></p>
<hr />
<table width="100%" cellpadding="0" cellspacing="2">
<tr>
<td bgcolor="#99CCFF"><a href="collections_19.html"><img border="0"
alt="ハッシュトライ" src="next.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_12.html"><img border="0"
alt="具象不変コレクションクラス" src="up.png" /></a></td>
<td bgcolor="#99CCFF"><a href="collections_17.html"><img border="0"
alt="不変キュー" src="previous.png" /></a></td>
<td align="center" bgcolor="#99CCFF" width="100%"><b>範囲</b></td>
<td bgcolor="#99CCFF" align="center" class="tocref"><a href=
"collections_49.html">目次</a></td>
</tr>
</table>
</body>
</html>