What will be the result of executing foldMap on List of Ints with identity function?
val l = List(1, 2, 3, 4, 5)

l.foldMap(identity)
Explanation
foldMap maps elements using provided function - in current example identity, which results in the same elements; then combines elements using Monoid of the result type: Monoid[Int]. If only mapping was performed, the result would be List(1, 2, 3, 4, 5). Performing combine results in sum of Ints, which is 15.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Scala
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести