We get a clearer definition of what it means to fold a type, then we look at the foldMap function

The ability to reply to discussions is limited to **PRO** members.
Want to join in the discussion? Click here to subscribe now.

2:50

We get a clearer definition of what it means to fold a type, then we look at the foldMap function

Watch this lesson now
Actually it wasn't clear on the very beginning why this code works:

const res2 = Map({brian: Sum(10), sara: Sum(2)})

.fold(Sum.empty())

but when you look into immutable-ext code

fold : function(empty) {

return this.foldMap(x => x, empty)

},

foldMap : function(f, empty) {

return empty != null

? this.reduce((acc, x) => acc.concat(f(x)), empty)

: this.reduce((acc, x) => acc.concat(f(x)))

},

and then into immutable js docs

reduce(

reducer: (reduction: R, value: V, key: K, iter: Iterable) => R,

initialReduction?: R,

context?: any

): R

Everything become more clearer ;)