インタラクションの実演例(解説つき)
scala> (1 to 10).sum // 階和
res0: Int = 55
scala> (1 to 10).product // 階乗
res1: Int = 3628800
scala> (1 to 10).map(_*2) // 各要素を2倍
res3: scala.collection.immutable.IndexedSeq[Int] = Vector(2, 4, 6, 8, 10, 12, 14
, 16, 18, 20)
scala> (1 to 10).reduce{(a,b)=>a*b} // productを使わない階乗
res4: Int = 3628800
scala> (1 to 10).reduce(_*_) // 別の記法(プレースホルダを使う)
res15: Int = 3628800
scala> BigInt(1) to 20
res6: scala.collection.immutable.NumericRagne.Inclusive[BigInt] = NumericRange(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
scala> (1 to 1000).map{_=>(math.random*1000).toInt}
res26: scala.collection.immutable.IndexedSeq[Int] = Vector(856, 247, 775, 828, 9
90, 277, 886, 485, 505, 651, 789, 393, 955, 95, 131, 951, 235, 173, 779, 875, 78
0, 890, 707, 190, 36, 422, 224, 751, 321, 652, 778, 241, 819, 379, 42, 218, 869,
343, 597, 928, 896, 487, 514, 272, 289, 219, 368, 550, 310, 761, 730, 325, 610,
82, 979, 36, 278, 308, 357, 795, 423, 965, 552, 136, 180, 872, 742, 356, 661, 1
7, 935, 477, 851, 301, 664, 809, 631, 577, 579, 535, 128, 47, 235, 742, 386, 693
, 429, 849, 879, 84, 771, 432, 782, 606, 771, 37, 991, 885, 643, 685, 826, 928,
162, 437, 32, 312, 401, 542, 149, 538, 883, 435, 577, 574, 711, 59, 724, 437, 55
2, 797, 388, 615, 882, 580, 154, 77, 829, 572, 960, 565, 24, 225, 133, 911, 346,
379, 126, 136, 118, 502, 944, 163, 304, 158, 703, 90, 540, 257, 71, 87, 362,...
scala> val ns = for(i<-1 to 10) yield i
ns: scala.collection.immutable.IndexedSeq[I or(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> ns.size
res1: Int = 10
scala> ns.length // size と意味は同じ
res2: Int = 10
scala> ns.length() // 括弧をつけるとNGなメソッドもある
<console>:9: error: Int does not take param
ns.length()
^
scala> ns.sum
res4: Int = 55
scala> ns.product
res5: Int = 3628800
scala> for(i<-1 to 10)yield i.length
<console>:8: error: value length is not a m nt
for(i<-1 to 10)yield i.length
^
scala> (for(i<-1 to 10)yield i).length
res7: Int = 10
scala> (for(i<-1 to 10)yield i).sum
res8: Int = 55
scala> (for(i<-1 to 10)yield i).product
res9: Int = 3628800
scala> 1 to 10 // これもcollectionの一種
res10: scala.collection.immutable.Range.Inc ange(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> 1.to(10) // メソッド呼出の書き方だとこうなる
res11: scala.collection.immutable.Range.Inc ange(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> 1.+(1) // 演算子 + も、実はメソッド
res12: Int = 2
scala> 1 + 1
res13: Int = 2
scala> 1+1
res14: Int = 2
scala> (1 to 10).map((i)=>i) // 意味のないmap呼出
res15: scala.collection.immutable.IndexedSe ector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> (1 to 10).map((i)=>i*i) // 2乗
res16: scala.collection.immutable.IndexedSe ector(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)
scala> (1 to 10).map((i)=>i*i*i) // 3乗
res17: scala.collection.immutable.IndexedSe ector(1, 8, 27, 64, 125, 216, 343, 512, 729
scala> (1 to 10).map{(i)=>i} // 書き方のバリエーション
res18: scala.collection.immutable.IndexedSe ector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> (1 to 10).map{i=>i} // 引数一つなら括弧省略可
res19: scala.collection.immutable.IndexedSe ector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> (1 to 10).map(i=>i) // 括弧でもOK
res20: scala.collection.immutable.IndexedSe ector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> (1 to 10).map(_)
<console>:8: error: missing parameter type
ed function ((x$1) => 1.to(10).map(x$1))
(1 to 10).map(_)
// 前節のように i=>i は使えるが、この式を _ で置き換えることは
// (これまでの類推だとできそうに見えるが) できない
scala> (1 to 10).map(indentity)
res21: scala.collection.immutable.IndexedSe ector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
// 長い名前だが identity という関数名を渡すことになる
scala> (1 to 10).toList
res23: List[Int] = List(1, 2, 3, 4, 5, 6, 7 )
scala> (1 to 10).toVector
res24: Vector[Int] = Vector(1, 2, 3, 4, 5,
, 10)
scala> (1 to 10).toArray
res25: Array[Int] = Array(1, 2, 3, 4, 5, 6, 10)
scala> (1 to 10).sum
res26: Int = 55
scala> (1 to 10).length
res27: Int = 10
scala> (1 to 10).product
res28: Int = 3628800
scala> (0 to 10).sum
res29: Int = 55
scala> (0 to 10).product
res30: Int = 0
scala> (0 to 10).ruduce // 引数が必要
<console>:8: error: value ruduce is not a m cala.collection.immutable.Range.Inclusive
(0 to 10).ruduce
^
scala> (0 to 10).ruduce((a,b)=>a*b) //これはタイプミスね
<console>:8: error: value ruduce is not a m cala.collection.immutable.Range.Inclusive
(0 to 10).ruduce((a,b)=>a*b)
^
scala> (0 to 10).reduce((a,b)=>a*b) // すべてかけ合わせる(と0になった)
res33: Int = 0
scala> (0 to 10).reduce
<console>:8: error: missing arguments for m ce in trait TraversableOnce;
follow this method with `_' if you want to
s a partially applied function
(0 to 10).reduce
^
scala> (0 to 10).reduce((a,b)=>a*b)
res35: Int = 0
scala> (1 to 10).reduce((a,b)=>a*b) // 階乗
res36: Int = 3628800
scala> (1 to 20).reduce((a,b)=>a*b) // 桁あふれ(オーバーフロー)発生
res37: Int = -2102132736
scala> (BigInt(1) to 20).reduce((a,b)=>a*b) // BigIntクラスを使えばOK
res38: BigInt = 2432902008176640000
scala> BigInt(1).to(20).reduce((a,b)=>a*b)
res39: BigInt = 2432902008176640000
scala> (BigInt(1) to 200).reduce((a,b)=>a*b res40: BigInt = 788657867364790503552363213 9513597768717326329474253324435944996340334 0119846239041772121389196388302576427902426 6624952829931113462857270763317237396988943 5166424025403329186413122742829485327752424 2403212574055795686602260319041703240623517 8922222789623703897374720000000000000000000 00000000000000000000
scala> math.random
res43: Double = 0.29434550746884525
scala> math.random(100) // Scalaではこの呼び方はNG
<console>:8: error: Double does not take pa rameters
math.random(100)
scala> (BigInt(1) to 20).reduce((a,b)=>a*b)
res45: BigInt = 2432902008176640000
scala> (BigInt(1) to 20).reduce(_*_)
res46: BigInt = 2432902008176640000
scala> for(i<-1 to 100)yield math.random // 乱数にょる数列
res47: scala.collection.immutable.IndexedSe q[Double] = Vector(0.6276835146886318, 0.94 2686531023402, 0.3198655610836568, 0.641661 0724747063, 0.06569053192529073, 0.83449553 69852749, 0.012680777348455186, 0.827972683 1350717, 0.2316674105751031, 0.040655446301 42581, 0.24703118911439148, 0.5304666342707 685, 0.7693217360087445, 0.3293150376171866 , 0.42456412005438227, 0.9179881281853925,
0.013472140313526282, 0.3714814305037548, 0 .7028867297868873, 0.8528719592255944, 0.80 59271367267126, 0.49546514690439913, 0.5295 905999701045, 0.5040707252346146, 0.4199959 501077184, 0.9458392336597004, 0.7053949465 650167, 0.06118675788285455, 0.392856397756 23193, 0.5811465074416169, 0.71166833768822 8, 0.017333432013489802, 0.2886372235992158 4, 0.9260351375070786, 0.5893467079431018,
0.9233224803277169, 0.5...
scala> for(i<-1 to 100)yield math.random // 呼ぶたびに数値は変わる
res48: scala.collection.immutable.IndexedSe q[Double] = Vector(0.5737623556478674, 0.63 98232780757501, 0.9394058667687093, 0.43072 694996781735, 0.7264400538238078, 0.7627142 510078255, 0.22378751429969168, 0.520099330 1902329, 0.31276556896795515, 0.80915095117 18566, 0.5328926762683353, 0.70529714228327 49, 0.5523842406228694, 0.966294930225203,
0.15409104787226813, 0.3689036531851825, 0. 5773893879367565, 0.12474593823447133, 0.11 373974317141011, 0.29306479433861854, 0.149 42826409911736, 0.4029351131798393, 0.62264 30143520841, 0.24723168435804588, 0.9309049 388407934, 0.3404912705921961, 0.3344746460 3808863, 0.12105103974995746, 0.57532550969 68635, 0.10594746984727776, 0.8213680141379 76, 0.8095872157235721, 0.781713891101317,
0.951850707625102, 0.3788872619939808, 0.89 88802467804404, 0.24415...
scala> for(i<-1 to 5)yield math.random
res49: scala.collection.immutable.IndexedSe q[Double] = Vector(0.13514094382461084, 0.8 915521009608091, 0.19038638042739187, 0.116 72802608856014, 0.734819997921352)
scala> for(i<-1 to 5)yield (math.random*100 0).toInt // 整数として乱数を使う
res51: scala.collection.immutable.IndexedSe q[Int] = Vector(70, 701, 196, 137, 81)
scala> for(i<-1 to 5)yield (math.random*100 0).toInt
res52: scala.collection.immutable.IndexedSe q[Int] = Vector(639, 64, 798, 680, 744)
scala> for(i<-1 to 5)yield (math.random*100 0)
res53: scala.collection.immutable.IndexedSe q[Double] = Vector(787.1647291332708, 427.2 6433487874027, 378.4107689060686, 555.06548 77425801, 534.1400121717503)
scala> for(i<-1 to 5)yield (math.random*100 0).toInt
res54: scala.collection.immutable.IndexedSe q[Int] = Vector(863, 566, 920, 393, 470)
scala> val rs=for(i<-1 to 100)yield (math.r andom*1000).toInt
rs: scala.collection.immutable.IndexedSeq[I nt] = Vector(624, 205, 541, 192, 421, 173,
856, 932, 437, 386, 331, 389, 631, 236, 542 , 792, 351, 406, 974, 274, 783, 620, 241, 7 47, 906, 59, 105, 243, 464, 698, 707, 627,
203, 113, 645, 493, 518, 53, 327, 827, 694, 127, 582, 715, 124, 531, 601, 980, 233, 64 5, 147, 123, 381, 650, 403, 371, 645, 74, 9 61, 936, 250, 324, 233, 824, 346, 783, 998, 664, 34, 50, 898, 47, 771, 233, 425, 828,
773, 992, 359, 682, 644, 193, 679, 958, 193 , 645, 669, 542, 344, 330, 332, 3, 122, 998 , 234, 776, 897, 735, 604, 501)
scala> rs.max
res55: Int = 998
scala> rs.min
res56: Int = 3
scala> rs.sum/rs.size // 平均値(正確ではない)
res57: Int = 499
scala> rs.sum
res58: Int = 49908
scala> rs.sum.toDouble/rs.size // 正確な平均値
res59: Double = 499.08
scala> 0.0+rs.sum/rs.size
res60: Double = 499.0
scala> (0.0+rs.sum)/rs.size
res61: Double = 499.08
scala> rs.reduce((a,b)=>if(a>b)a else b) // reduceで最大値を求めるとしたら
res62: Int = 998
scala> rs.reduce((a,b)=>if(a<b)a else b)
res63: Int = 3
scala> rs
res64: scala.collection.immutable.IndexedSeqctor(624, 205, 541, 192, 421, 173, 856, 932, 331, 389, 631, 236, 542, 792, 351, 406, 974, 620, 241, 747, 906, 59, 105, 243, 464, 698, 203, 113, 645, 493, 518, 53, 327, 827, 694, 715, 124, 531, 601, 980, 233, 645, 147, 120, 403, 371, 645, 74, 961, 936, 250, 324, 236, 783, 998, 664, 34, 50, 898, 47, 771, 233, 773, 992, 359, 682, 644, 193, 679, 958, 193, 542, 344, 330, 332, 3, 122, 998, 234, 776, 604, 501)
scala> rs.foreach(println)
624
205
// 長い出力なので中略
735
604
501
scala> rs.foreach(println(_))
624
205
// 長い出力なので中略
735
604
501
scala> rs.foreach(println)
624
205
// 長い出力なので中略
735
604
501
scala> rs.isEmpty
res68: Boolean = false
scala> rs.nonEmpty
res69: Boolean = true
scala> rs.ind
indexOf indexOfSlice indexWhere indice
scala> rs.indexOf(1)
res70: Int = -1
scala> rs.indexOf(2)
res71: Int = -1
scala> rs.indexOf(3)
res72: Int = 91
scala> rs.indexOf(rs.max)
res73: Int = 66
scala> rs.indexOf(rs.min)
res74: Int = 91
scala> rs
res75: scala.collection.immutable.IndexedSeqctor(624, 205, 541, 192, 421, 173, 856, 932, 331, 389, 631, 236, 542, 792, 351, 406, 974, 620, 241, 747, 906, 59, 105, 243, 464, 698, 203, 113, 645, 493, 518, 53, 327, 827, 694, 715, 124, 531, 601, 980, 233, 645, 147, 120, 403, 371, 645, 74, 961, 936, 250, 324, 236, 783, 998, 664, 34, 50, 898, 47, 771, 233, 773, 992, 359, 682, 644, 193, 679, 958, 193, 542, 344, 330, 332, 3, 122, 998, 234, 776, 604, 501)
scala> rs.lastIndexOf(rs.min)
res76: Int = 91
scala> rs.lastIndexOf(rs.max)
res77: Int = 93
scala> rs.filter((a)=>a%2==0)
res78: scala.collection.immutable.IndexedSeqctor(624, 192, 856, 932, 386, 236, 542, 792, 274, 620, 906, 464, 698, 518, 694, 582, 124, 74, 936, 250, 324, 824, 346, 998, 664, 34,828, 992, 682, 644, 958, 542, 344, 330, 332, 234, 776, 604)
scala> rs.filter(_%2==0)
res79: scala.collection.immutable.IndexedSeqctor(624, 192, 856, 932, 386, 236, 542, 792, 274, 620, 906, 464, 698, 518, 694, 582, 124, 74, 936, 250, 324, 824, 346, 998, 664, 34,828, 992, 682, 644, 958, 542, 344, 330, 332, 234, 776, 604)
scala> rs.filter(_%2!=0)
res80: scala.collection.immutable.IndexedSeqctor(205, 541, 421, 173, 437, 331, 389, 631, 241, 747, 59, 105, 243, 707, 627, 203, 113, 53, 327, 827, 127, 715, 531, 601, 233, 645, 381, 403, 371, 645, 961, 233, 783, 47, 771, 773, 359, 193, 679, 193, 645, 669, 3, 897,
scala> rs.partition(_%2==0)
res81: (scala.collection.immutable.IndexedSeala.collection.immutable.IndexedSeq[Int]) = 4, 192, 856, 932, 386, 236, 542, 792, 406, 920, 906, 464, 698, 518, 694, 582, 124, 980, 36, 250, 324, 824, 346, 998, 664, 34, 50, 892, 682, 644, 958, 542, 344, 330, 332, 122, 976, 604),Vector(205, 541, 421, 173, 437, 331, 351, 783, 241, 747, 59, 105, 243, 707, 627, 645, 493, 53, 327, 827, 127, 715, 531, 601, 147, 123, 381, 403, 371, 645, 961, 233, 78, 233, 425, 773, 359, 193, 679, 193, 645, 66 735, 501))
scala> rs.sort // 順序つけて並び替えるメソッド、なぜか 単純な動詞 sort ではなく
<console>:9: error: value sort is not a memba.collection.immutable.IndexedSeq[Int]
rs.sort
^
scala> rs.sorted // sorted という名前が使われている
res83: scala.collection.immutable.IndexedSeqctor(3, 34, 47, 50, 53, 59, 74, 105, 113, 124, 127, 147, 173, 192, 193, 193, 203, 205, 233, 234, 236, 241, 243, 250, 274, 324, 327, 332, 344, 346, 351, 359, 371, 381, 386, 389, 421, 425, 437, 464, 493, 501, 518, 531, 541, 582, 601, 604, 620, 624, 627, 631, 644, 645, 645, 650, 664, 669, 679, 682, 694, 698, 735, 747, 771, 773, 776, 783, 783, 792, 824, 856, 897, 898, 906, 932, 936, 958, 961, 974, 998, 998)
scala> rs.sorted.last // これも最大値を得る方法の1つ
res84: Int = 998
scala> rs.sorted.first
<console>:9: error: value first is not a memla.collection.immutable.IndexedSeq[Int]
rs.sorted.first
^
scala> rs.sorted.top
<console>:9: error: value top is not a membe.collection.immutable.IndexedSeq[Int]
rs.sorted.top
^
scala> rs.sorted.last
res87: Int = 998
scala> rs.sorted
res88: scala.collection.immutable.IndexedSeqctor(3, 34, 47, 50, 53, 59, 74, 105, 113, 124, 127, 147, 173, 192, 193, 193, 203, 205, 233, 234, 236, 241, 243, 250, 274, 324, 327, 332, 344, 346, 351, 359, 371, 381, 386, 389, 421, 425, 437, 464, 493, 501, 518, 531, 541, 582, 601, 604, 620, 624, 627, 631, 644, 645, 645, 650, 664, 669, 679, 682, 694, 698, 735, 747, 771, 773, 776, 783, 783, 792, 824, 856, 897, 898, 906, 932, 936, 958, 961, 974, 998, 998)
scala> rs.sorted(0) // 次の式(topと同じ)と、意味が違う
<console>:9: error: type mismatch;
found : Int(0)
required: scala.math.Ordering[?]
rs.sorted(0)
^
scala> (rs.sorted)(0)
<console>:9: error: type mismatch;
found : Int(0)
required: scala.math.Ordering[?]
(rs.sorted)(0)
^
scala> rs.sorted.last
res91: Int = 998
scala> rs.sorted
res92: scala.collection.immutable.IndexedSeqctor(3, 34, 47, 50, 53, 59, 74, 105, 113, 124, 127, 147, 173, 192, 193, 193, 203, 205, 233, 234, 236, 241, 243, 250, 274, 324, 327, 332, 344, 346, 351, 359, 371, 381, 386, 389, 421, 425, 437, 464, 493, 501, 518, 531, 541, 582, 601, 604, 620, 624, 627, 631, 644, 645, 645, 650, 664, 669, 679, 682, 694, 698, 735, 747, 771, 773, 776, 783, 783, 792, 824, 856, 897, 898, 906, 932, 936, 958, 961, 974, 998, 998)
scala> rs.sort // 途中で Tab を叩いてみたところ
sortBy sortWith sorted
scala> rs.sort
sortBy sortWith sorted
scala> rs.sortWith((a,b)=>a<b)
res93: scala.collection.immutable.IndexedSeqctor(3, 34, 47, 50, 53, 59, 74, 105, 113, 124, 127, 147, 173, 192, 193, 193, 203, 205, 233, 234, 236, 241, 243, 250, 274, 324, 327, 332, 344, 346, 351, 359, 371, 381, 386, 389, 421, 425, 437, 464, 493, 501, 518, 531, 541, 582, 601, 604, 620, 624, 627, 631, 644, 645, 645, 650, 664, 669, 679, 682, 694, 698, 735, 747, 771, 773, 776, 783, 783, 792, 824, 856, 897, 898, 906, 932, 936, 958, 961, 974, 998, 998)
scala> rs.sortWith((a,b)=>a<b)
res94: scala.collection.immutable.IndexedSeqctor(3, 34, 47, 50, 53, 59, 74, 105, 113, 124, 127, 147, 173, 192, 193, 193, 203, 205, 233, 234, 236, 241, 243, 250, 274, 324, 327, 332, 344, 346, 351, 359, 371, 381, 386, 389, 421, 425, 437, 464, 493, 501, 518, 531, 541, 582, 601, 604, 620, 624, 627, 631, 644, 645, 645, 650, 664, 669, 679, 682, 694, 698, 735, 747, 771, 773, 776, 783, 783, 792, 824, 856, 897, 898, 906, 932, 936, 958, 961, 974, 998, 998)
scala> rs.sortWith((a,b)=>a>b)
res95: scala.collection.immutable.IndexedSeqctor(998, 998, 992, 980, 974, 961, 958, 936, 898, 897, 856, 828, 827, 824, 792, 783, 783, 771, 747, 735, 715, 707, 698, 694, 682, 674, 650, 645, 645, 645, 645, 644, 631, 627, 604, 601, 582, 542, 542, 541, 531, 518, 501, 437, 425, 421, 406, 403, 389, 386, 381, 371, 346, 344, 332, 331, 330, 327, 324, 274, 250, 236, 234, 233, 233, 233, 205, 203, 193, 193, 147, 127, 124, 123, 122, 113, 105, 74, 5947, 34, 3)
scala> rs.sorted
res96: scala.collection.immutable.IndexedSeqctor(3, 34, 47, 50, 53, 59, 74, 105, 113, 124, 127, 147, 173, 192, 193, 193, 203, 205, 233, 234, 236, 241, 243, 250, 274, 324, 327, 332, 344, 346, 351, 359, 371, 381, 386, 389, 421, 425, 437, 464, 493, 501, 518, 531, 541, 582, 601, 604, 620, 624, 627, 631, 644, 645, 645, 650, 664, 669, 679, 682, 694, 698, 735, 747, 771, 773, 776, 783, 783, 792, 824, 856, 897, 898, 906, 932, 936, 958, 961, 974, 998, 998)
scala> rs.sorted.reverse
res97: scala.collection.immutable.IndexedSeqctor(998, 998, 992, 980, 974, 961, 958, 936, 898, 897, 856, 828, 827, 824, 792, 783, 783, 771, 747, 735, 715, 707, 698, 694, 682, 674, 650, 645, 645, 645, 645, 644, 631, 627, 604, 601, 582, 542, 542, 541, 531, 518, 501, 437, 425, 421, 406, 403, 389, 386, 381, 371, 346, 344, 332, 331, 330, 327, 324, 274, 250, 236, 234, 233, 233, 233, 205, 203, 193, 193, 147, 127, 124, 123, 122, 113, 105, 74, 5947, 34, 3)
scala> rs.sorted.reverse.reverse.reverse
res98: scala.collection.immutable.IndexedSeqctor(998, 998, 992, 980, 974, 961, 958, 936, 898, 897, 856, 828, 827, 824, 792, 783, 783, 771, 747, 735, 715, 707, 698, 694, 682, 674, 650, 645, 645, 645, 645, 644, 631, 627, 604, 601, 582, 542, 542, 541, 531, 518, 501, 437, 425, 421, 406, 403, 389, 386, 381, 371, 346, 344, 332, 331, 330, 327, 324, 274, 250, 236, 234, 233, 233, 233, 205, 203, 193, 193, 147, 127, 124, 123, 122, 113, 105, 74, 5947, 34, 3)
scala> rs.sorted.reverse.reverse.reverse.revres99: scala.collection.immutable.IndexedSeqctor(3, 34, 47, 50, 53, 59, 74, 105, 113, 124, 127, 147, 173, 192, 193, 193, 203, 205, 233, 234, 236, 241, 243, 250, 274, 324, 327, 332, 344, 346, 351, 359, 371, 381, 386, 389, 421, 425, 437, 464, 493, 501, 518, 531, 541, 582, 601, 604, 620, 624, 627, 631, 644, 645, 645, 650, 664, 669, 679, 682, 694, 698, 735, 747, 771, 773, 776, 783, 783, 792, 824, 856, 897, 898, 906, 932, 936, 958, 961, 974, 998, 998)
scala> rs.filter(_<100)
res100: scala.collection.immutable.IndexedSeector(59, 53, 74, 34, 50, 47, 3)
scala> rs.filter(_<100)
res101: scala.collection.immutable.IndexedSeq[Int] = Vector(59, 53, 74, 34, 50, 47, 3)
scala> rs.filter(_.toString.length==2)
res102: scala.collection.immutable.IndexedSeq[Int] = Vector(59, 53, 74, 34, 50, 47)
scala>