// // simple demo of using loops to operate on lists // println("type in list values (integers), quit to end") val list = fillList() printList(list); println("sum is " + listCombine(list, (x,y)=>(x+y), 0)) println("product is " + listCombine(list, (x,y)=>(x*y), 1)) println("min is " + listCombine(list, (x,y) => (x min y), Int.MaxValue)) println("max is " + listCombine(list, (x,y) => (x max y), Int.MinValue)) def fillList() : List[Int] = { var input = readLine var result = List[Int]() while (input != "quit") { result = input.toInt :: result input = readLine } result.reverse } def printList(list : List[Int]) { for (elem <- list) println(elem) } def listCombine(list : List[Int], combine : (Int, Int) => Int, identity : Int) : Int = { var result = identity for (elem <- list) result = combine(result, elem) result }