Introduction to Scala Part2 : Collections
Bubu
4,757 views
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
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Suggested playgrounds
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]) = ???
}