scala> List(1,4,3) res0: List[Int] = List(1, 4, 3) scala> val l = List(1,4,3) l: List[Int] = List(1, 4, 3) scala> l res1: List[Int] = List(1, 4, 3) scala> l. ++ flatten minBy sortWith ++: fold mkString sorted +: foldLeft nonEmpty span /: foldRight orElse splitAt :+ forall padTo startsWith :: foreach par stringPrefix ::: genericBuilder partition sum :\ groupBy patch tail addString grouped permutations tails aggregate hasDefiniteSize prefixLength take andThen head product takeRight apply headOption productArity takeWhile applyOrElse indexOf productElement to asInstanceOf indexOfSlice productIterator toArray canEqual indexWhere productPrefix toBuffer collect indices reduce toIndexedSeq collectFirst init reduceLeft toIterable combinations inits reduceLeftOption toIterator companion intersect reduceOption toList compose isDefinedAt reduceRight toMap contains isEmpty reduceRightOption toSeq containsSlice isInstanceOf repr toSet copyToArray isTraversableAgain reverse toStream copyToBuffer iterator reverseIterator toString corresponds last reverseMap toTraversable count lastIndexOf reverse_::: toVector diff lastIndexOfSlice runWith transpose distinct lastIndexWhere sameElements union drop lastOption scan unzip dropRight length scanLeft unzip3 dropWhile lengthCompare scanRight updated endsWith lift segmentLength view exists map seq withFilter filter mapConserve size zip filterNot max slice zipAll find maxBy sliding zipWithIndex flatMap min sortBy scala> 10 :: l res2: List[Int] = List(10, 1, 4, 3) scala> 14 :: 10 :: List() res3: List[Int] = List(14, 10) scala> 14 :: 10 :: Nil res4: List[Int] = List(14, 10) scala> l :+ 66 res5: List[Int] = List(1, 4, 3, 66) scala> l.length res6: Int = 3 scala> List(1,2) ::: List(5,9) res7: List[Int] = List(1, 2, 5, 9) scala> List(1,2) == List(1,2) res8: Boolean = true scala> List(1,2) == List(1,3) res9: Boolean = false scala> List(1,2) != List(1,2) res10: Boolean = false scala> List(1,2) == 1 :: List(2) res11: Boolean = true scala> l.equals(List(1,2)) res12: Boolean = false scala> l res13: List[Int] = List(1, 4, 3) scala> l.take(2) res14: List[Int] = List(1, 4) scala> l take 2 res15: List[Int] = List(1, 4) scala> 1 + 2 res16: Int = 3 scala> 1.+(2) res17: Int = 3 scala> l drop 2 res18: List[Int] = List(3) scala> l splitAt 2 res19: (List[Int], List[Int]) = (List(1, 4),List(3)) scala> l res20: List[Int] = List(1, 4, 3) scala> val c = l splitAt 2 c: (List[Int], List[Int]) = (List(1, 4),List(3)) scala> c._1 res21: List[Int] = List(1, 4) scala> c._2 res22: List[Int] = List(3) scala> val c = l splitAt 0 c: (List[Int], List[Int]) = (List(),List(1, 4, 3)) scala> val c = l splitAt 1 c: (List[Int], List[Int]) = (List(1),List(4, 3)) scala> val c = l splitAt 10 c: (List[Int], List[Int]) = (List(1, 4, 3),List()) scala> l.head res23: Int = 1 scala> l.tail res24: List[Int] = List(4, 3) scala> l drop 1 res25: List[Int] = List(4, 3) scala> l tail warning: there was one feature warning; re-run with -feature for details res26: List[Int] = List(4, 3) scala> l.reverse res27: List[Int] = List(3, 4, 1) scala> l(1) res28: Int = 4 scala> l(0) res29: Int = 1 scala> l(3) java.lang.IndexOutOfBoundsException: 3 at scala.collection.LinearSeqOptimized$class.apply(LinearSeqOptimized.scala:65) at scala.collection.immutable.List.apply(List.scala:84) ... 33 elided scala> l(2) res31: Int = 3 scala> List.range(1,10) res32: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9) scala> l res33: List[Int] = List(1, 4, 3) scala> l.filter filter filterNot scala> l.filter(x => x%2 != 0) res34: List[Int] = List(1, 3) scala> l.filter(_%2 != 0) res35: List[Int] = List(1, 3) scala> l.map(x => 10*x) res36: List[Int] = List(10, 40, 30) scala> l.map(x => "T"+x) res37: List[String] = List(T1, T4, T3) scala> l.map(10*_) res38: List[Int] = List(10, 40, 30) scala> l.exists(_<0) res39: Boolean = false scala> l.exists(_==0) res40: Boolean = false scala> l.exists(_>0) res41: Boolean = true scala> l.forall(_>0) res42: Boolean = true scala> l.forall(_<0) res43: Boolean = false scala> l.foreach(x => println(x)) 1 4 3 scala> l.foreach(println(_)) 1 4 3 scala> l.foreach(x => println(x+100)) 101 104 103 scala> l.foreach(x => println(_+100)) :12: error: missing parameter type for expanded function ((x$1) => x$1.$plus(100)) l.foreach(x => println(_+100)) ^ scala> l.map(_+1) res48: List[Int] = List(2, 5, 4) scala> l.map(_) :12: error: missing parameter type for expanded function ((x$1) => l.map(x$1)) l.map(_) ^ scala> l.map(x=>x) res50: List[Int] = List(1, 4, 3) scala> l.map(identity) res51: List[Int] = List(1, 4, 3) scala> l.reduce(_+_) res52: Int = 8 scala> l.reduce(_-_) res53: Int = -6 scala> def fact(n:Int) = List.range(1,n+1).reduce(_*_) fact: (n: Int)Int scala> fact(6) res54: Int = 720 scala> l res55: List[Int] = List(1, 4, 3) scala> List(1).reduce(_+_) res56: Int = 1 scala> List(0).reduce(_+_) res57: Int = 0 scala> List().reduce(_+_) :11: error: missing parameter type for expanded function ((x$1, x$2) => x$1.$plus(x$2)) List().reduce(_+_) ^ :11: error: missing parameter type for expanded function ((x$1: , x$2) => x$1.$plus(x$2)) List().reduce(_+_) ^ scala> l.reduce((x,y)=>x+y) res59: Int = 8 scala> l.reduce((x:Int,y:Int)=>x+y) res60: Int = 8 scala> l.reduce((x,y) => if (x>y) x else y) res61: Int = 4 scala> 3 max 9 res62: Int = 9 scala> l.reduce(_ max _) res63: Int = 4 scala> List(1,2,3) zip List("uno","due","tre") res64: List[(Int, String)] = List((1,uno), (2,due), (3,tre)) scala> l.zip(List.range(0,l.length)) res65: List[(Int, Int)] = List((1,0), (4,1), (3,2)) scala> l.zip(List.range(0,l.length)).filter(c => c._2 % 2 != 0) res66: List[(Int, Int)] = List((4,1)) scala> val l = List("uno", "due", "tre", "quattro") l: List[String] = List(uno, due, tre, quattro) scala> l.zip(List.range(0,l.length)).filter(c => c._2 % 2 != 0) res67: List[(String, Int)] = List((due,1), (quattro,3)) scala> l.zip(List.range(0,l.length)).filter(c => c._2 % 2 != 0).map(c => c._1) res68: List[String] = List(due, quattro) scala> def lunghezza(l:List[Int]):Int = { | if (l == Nil) 0 else 1 + lunghezza(l.tail) | } lunghezza: (l: List[Int])Int scala> lunghezza(List(1,3,5,2,1)) res69: Int = 5 scala> def miaSomma(x:Int, y:Int) = { | println(x+"+"+y+"=="+(x+y)) | x+y | } miaSomma: (x: Int, y: Int)Int scala> List(2,1,4,3,5).reduce(miaSomma) 2+1==3 3+4==7 7+3==10 10+5==15 res70: Int = 15 scala> List(2,1,4,3,5).reduceRight(miaSomma) 3+5==8 4+8==12 1+12==13 2+13==15 res71: Int = 15 scala> def merge(a:List[Int], b:List[Int]):List[Int] = { | if (a==Nil) b | else if (b==Nil) a | else if (a.head < b.head) a.head :: merge(a.tail,b) | else b.head :: merge(a,b.tail) | } merge: (a: List[Int], b: List[Int])List[Int] scala> merge(List(1,5,7), List(3,4,9)) res72: List[Int] = List(1, 3, 4, 5, 7, 9) scala> def mergeSort(v:List[Int]):List[Int] = { | if (v.length < 2) v | else { | val (l,r) = v.splitAt(v.length/2) | merge(mergeSort(l), mergeSort(r)) | } | } mergeSort: (v: List[Int])List[Int] scala> mergeSort(List()) res73: List[Int] = List() scala> mergeSort(List(1)) res74: List[Int] = List(1) scala> mergeSort(List(2,1)) res75: List[Int] = List(1, 2) scala> mergeSort(List(2,6,3,9,1,5,8)) res76: List[Int] = List(1, 2, 3, 5, 6, 8, 9) scala> def prendiIndicePari(l:List[Int]) = { |