x1. おまけ

Scala の メソッド は、

・引数が0個の場合は、メソッド名の後ろの ( ) を省略できる。

・オブジェクト と メソッド と 引数 を 演算子 の様に中間記法で表記できる。

・演算子 を メソッド呼び出しの表記法で利用できる。(実は演算子は ただのメソッド)

・メソッドの部分適用から関数オブジェクトを得ることが出来る。

scala> def a() = 123
a: ()Int
scala> a()
res0: Int = 123
scala> a
res1: Int = 123
scala> object o { def a()=234; def b(x:Int) = x}
defined object o
scala> o.a
res2: Int = 234
scala> o.b(345)
res3: Int = 345
scala> o b 345
res4: Int = 345

scala> o.b(_:Int)

res6: Int => Int = <function1>
scala> o.b(_:Int)(456)
<console>:9: error: Int does not take parameters
              o.b(_:Int)(456)
                        ^
scala> (o.b(_:Int))(456)
res8: Int = 456
scala> object oo { def c(x:Int,y:Int) = x-y}
defined object oo
scala> oo.c(_:Int,_:Int)
res9: (Int, Int) => Int = <function2>
scala> oo.c(_:Int,_:Int).curried
<console>:9: error: value curried is not a member of Int
              oo.c(_:Int,_:Int).curried
                                ^
scala> (oo.c(_:Int,_:Int)).curried
res11: Int => (Int => Int) = <function1>
scala> (oo.c(_:Int,_:Int)).curried 1 2
<console>:1: error: ';' expected but integer literal found.
       (oo.c(_:Int,_:Int)).curried 1 2
                                   ^
scala> (oo.c(_:Int,_:Int)).curried (1) (2)
res12: Int = -1
scala> object ooo { def c(x:Int)(y:Int) = x-y}
defined object ooo

scala> ooo.c (1)

<console>:9: error: missing arguments for method c in object ooo;

follow this method with `_' if you want to treat it as a partially applied function

              ooo.c (1)
                    ^
scala> ooo.c (1) (2)
res15: Int = -1
scala> (ooo.c (1)) (2)
res16: Int = -1
scala> ooo.c(1) (_:Int)
res17: Int => Int = <function1>

scala> val aaa = ooo.c(1) (_:Int)

aaa: Int => Int = <function1>
scala> aaa (1)
res18: Int = 0
Stream
// 0 1 2 3 の遅延ストリーム
Stream.from(0)
val ls = List(1,2,3)
val ss = Stream(4,5,6)
scala> ls ::: ls
List[Int] = List(1, 2, 3, 1, 2, 3)
scala> ls.toStream #::: ss
res5: scala.collection.immutable.Stream[Int] = Stream(1, ?)
関数の引数の名前渡しで遅延評価
def f( a:Int , b: => Int)