Introduction to Scala Part2 : Collections
Bubu
6,478 views
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Traversable: Folds
- Operations: foldLeft, foldRight, /:, :, reduceLeft, reduceRight
- Goal: apply a binary operation to successive elements.
return sum of a List
return the min value of a List
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package fp101.tp02.collections
object ExerciceFold {
/**
*
* Using List.foldLeft
*
* return the sum of an Integer List
*/
def sumFoldLeft(l: List[Int]) = ???
/**
*
* Using reduceRight
*
*
* return the min value of the List
*
* scala doc:
*
* def reduceRight[B >: A](op: (A, B) ⇒ B): B
* Applies a binary operator to all elements of this sequence, going right to left.
*/
def minReduceRight(l: List[Int]) = ???
}
Enter to Rename, Shift+Enter to Preview