scala> val l = List(1, 2, 3) l: List[Int] = List(1, 2, 3) scala> val a = Tuple2(1, 2, 3) :11: error: too many arguments (3) for method apply: (_1: T1, _2: T2)(T1, T2) in object Tuple2 val a = Tuple2(1, 2, 3) ^ scala> val a = Tuple2(1, "one") a: (Int, String) = (1,one) scala> val a = (1, "one") a: (Int, String) = (1,one) scala> val a = 1 -> "one" a: (Int, String) = (1,one) scala> a. _1 copy invert productIterator toString _2 equals productArity productPrefix zipped canEqual hashCode productElement swap scala> a._1 res0: Int = 1 scala> a._2 res1: String = one scala> val x = a._1 x: Int = 1 scala> val y = a._2 y: String = one scala> val (x, y) = a x: Int = 1 y: String = one scala> x + 2 res2: Int = 3 scala> x.+(2) res3: Int = 3 scala> val double = (x: Int) => x * 2 double: Int => Int = $$Lambda$1389/611587518@48dc9950 scala> double. andThen apply compose toString scala> double.apply def apply(v1: Int): Int scala> double.apply(2) res4: Int = 4 scala> double.apply(3) res5: Int = 6 scala> double(3) res6: Int = 6 scala> def doubleMethod(x: Int) = x * 2 doubleMethod: (x: Int)Int scala> doubleMethod(3) res7: Int = 6 scala> doubleMethod.apply(3) :13: error: missing argument list for method doubleMethod Unapplied methods are only converted to functions when a function type is expected. You can make this conversion explicit by writing `doubleMethod _` or `doubleMethod(_)` instead of `doubleMethod`. doubleMethod.apply(3) ^ scala> val doubleFunction = doubleMethod :12: error: missing argument list for method doubleMethod Unapplied methods are only converted to functions when a function type is expected. You can make this conversion explicit by writing `doubleMethod _` or `doubleMethod(_)` instead of `doubleMethod`. val doubleFunction = doubleMethod ^ scala> val doubleFunction = doubleMethod _ doubleFunction: Int => Int = $$Lambda$1401/1826467916@1c6d65f7 scala> val doubleFunction = (x: Int) => doubleMethod(x) doubleFunction: Int => Int = $$Lambda$1402/604500392@2fc94125 scala> doubleFunction.apply(3) res9: Int = 6 scala> (doubleMethod _).apply(3) res10: Int = 6 scala> l res11: List[Int] = List(1, 2, 3) scala> l.map(doubleFunction) res12: List[Int] = List(2, 4, 6) scala> l.map(double) res13: List[Int] = List(2, 4, 6) scala> l.map(doubleMethod _) res14: List[Int] = List(2, 4, 6) scala> l.map(doubleMethod) res15: List[Int] = List(2, 4, 6) scala> l.map((x: Int) => doubleMethod(x)) res16: List[Int] = List(2, 4, 6) scala> l.map(x => doubleMethod(x)) res17: List[Int] = List(2, 4, 6) scala> l.map(x => x * 2) res18: List[Int] = List(2, 4, 6) scala> l.map(_ * 2) res19: List[Int] = List(2, 4, 6) scala> val f: Int => Int = _ * 2 f: Int => Int = $$Lambda$1427/138732283@1abd158 scala> l.map(f) res20: List[Int] = List(2, 4, 6) scala> l. ++ flatMap min sortBy ++: flatten minBy sortWith +: fold mkString sorted /: foldLeft nonEmpty span :+ foldRight orElse splitAt :: forall padTo startsWith ::: foreach par stringPrefix :\ genericBuilder partition sum WithFilter groupBy patch tail addString grouped permutations tails aggregate hasDefiniteSize prefixLength take andThen hashCode product takeRight apply head productArity takeWhile applyOrElse headOption productElement to canEqual indexOf productIterator toArray collect indexOfSlice productPrefix toBuffer collectFirst indexWhere reduce toIndexedSeq combinations indices reduceLeft toIterable companion init reduceLeftOption toIterator compose inits reduceOption toList contains intersect reduceRight toMap containsSlice isDefinedAt reduceRightOption toSeq copyToArray isEmpty repr toSet copyToBuffer isTraversableAgain reverse toStream corresponds iterator reverseIterator toString count last reverseMap toTraversable diff lastIndexOf reverse_::: toVector distinct lastIndexOfSlice runWith transpose drop lastIndexWhere sameElements union dropRight lastOption scan unzip dropWhile length scanLeft unzip3 endsWith lengthCompare scanRight updated equals lift segmentLength view exists map seq withFilter filter mapConserve size zip filterNot max slice zipAll find maxBy sliding zipWithIndex scala> l.sum res21: Int = 6 scala> l.foldRight override def foldRight[B](z: B)(op: (Int, B) => B): B scala> l.foldRight[Int](0)((cur: Int, acc: Int) => cur + acc) res22: Int = 6 scala> l.foldRight[Int](1)((cur: Int, acc: Int) => cur * acc) res23: Int = 6 scala> val l = List(1, 2, 3, 4) l: List[Int] = List(1, 2, 3, 4) scala> l.foldRight[Int](0)((cur: Int, acc: Int) => cur + acc) res24: Int = 10 scala> l.foldRight[Int](1)((cur: Int, acc: Int) => cur * acc) res25: Int = 24 scala> l.product product productArity productElement productIterator productPrefix scala> l.product res26: Int = 24 scala> l.foldRight[Int](0)(_ + _) res27: Int = 10 scala> l.foldRight[Int](1)(_ * _) res28: Int = 24 scala> val add = (x: Int, y: Int) => x + y add: (Int, Int) => Int = $$Lambda$1483/1589382133@6561e48 scala> l.foldRight[Int](0)(add) res29: Int = 10 scala> add(42, 24) res30: Int = 66 scala> val tuple = (42, 24) tuple: (Int, Int) = (42,24) scala> add(tuple) :14: error: not enough arguments for method apply: (v1: Int, v2: Int)Int in trait Function2. Unspecified value parameter v2. add(tuple) ^ scala> val addTuple = (tuple: (Int, Int)) => tuple._1 + tuple._2 addTuple: ((Int, Int)) => Int = $$Lambda$1507/1760511301@49b60cc3 scala> addTuple(tuple) res32: Int = 66 scala> add(42, 24) res33: Int = 66 scala> addTuple((42, 24)) res34: Int = 66 scala> addTuple(42, 24) res35: Int = 66 scala> val l = List(1, 2, 3) l: List[Int] = List(1, 2, 3) scala> List(1, 1, 2, 2, 3, 3) res36: List[Int] = List(1, 1, 2, 2, 3, 3) scala> l.map(x => List(x, x)) res37: List[List[Int]] = List(List(1, 1), List(2, 2), List(3, 3)) scala> l.map(x => List(x, x)).flatten res38: List[Int] = List(1, 1, 2, 2, 3, 3) scala> l.flatMap(x => List(x, x)) res39: List[Int] = List(1, 1, 2, 2, 3, 3) scala> def mp[A, B](l: List[A], f: A => B): List[B] = l.map(f) mp: [A, B](l: List[A], f: A => B)List[B] scala> def mp[A, B](l: List[A], f: A => B): List[B] = l.flatMap(x => List(x)) :13: error: type mismatch; found : List[A] required: List[B] def mp[A, B](l: List[A], f: A => B): List[B] = l.flatMap(x => List(x)) ^ scala> def mp[A, B](l: List[A], f: A => B): List[B] = l.flatMap(x => List(f(x))) mp: [A, B](l: List[A], f: A => B)List[B] scala> mp(l, double) res40: List[Int] = List(2, 4, 6) scala> def duplicate[A](l: List[A]): List[A] = l.flatMap(x => List(x, x)) duplicate: [A](l: List[A])List[A] scala> d :12: error: not found: value d d ^ scala> duplicate(l) res42: List[Int] = List(1, 1, 2, 2, 3, 3) scala> l.flatten :13: error: No implicit view available from Int => scala.collection.GenTraversableOnce[B]. l.flatten ^ scala> l.filter(x => x < 3) res44: List[Int] = List(1, 2) scala> def filter[A](l: List[A], p: A => Boolean): List[A] = l.filter(p) filter: [A](l: List[A], p: A => Boolean)List[A] scala> def filter[A](l: List[A], p: A => Boolean): List[A] = l.flatMap(x => if(p(x)) List(x) else List()) filter: [A](l: List[A], p: A => Boolean)List[A] scala> filter(l, (x: Int) => x < 3) res45: List[Int] = List(1, 2) scala> def filter[A](l: List[A], p: A => Boolean): List[A] = l.flatMap(x => if(p(x)) List(x, x) else List(x)) filter: [A](l: List[A], p: A => Boolean)List[A] scala> filter(l, (x: Int) => x < 3) res46: List[Int] = List(1, 1, 2, 2, 3) scala> def filter[A](l: List[A], p: A => Boolean): List[A] = l.flatMap(x => if(p(x)) List(x) else List()) filter: [A](l: List[A], p: A => Boolean)List[A] scala> filter(l, (x: Int) => x < 3) res47: List[Int] = List(1, 2) scala> l.foldRight[Int](0)((cur: Int, acc: Int) => cur + acc) res48: Int = 6 scala> l.foldRight[String]("0")((cur: Int, acc: String) => cur.toString + " + " + acc) res49: String = 1 + 2 + 3 + 0 scala> l.foldRight[String]("0")((cur: Int, acc: String) => "( " + cur.toString + " + " + acc + " )") res50: String = ( 1 + ( 2 + ( 3 + 0 ) ) ) scala> l.foldLeft[String]("0")((acc: String, cur: Int) => "( " + acc + " + " + cur.toString + " )") res51: String = ( ( ( 0 + 1 ) + 2 ) + 3 )