2013-07-25から1日間の記事一覧
+=:で末尾に要素を追加できる。 scala> import scala.collection.mutable.ListBuffer import scala.collection.mutable.ListBuffer scala> val buf = new ListBuffer[Int] buf: scala.collection.mutable.ListBuffer[Int] = ListBuffer() scala> buf += 1 re…
def append[T](xs: List[T], ys: List[T]): List[T] = xs match { case List() => ys case x :: xs1 => x :: append(xs1, xs) } パターンマッチ使って再帰使うと、とてもScalaっぽい。