Skip to content

Commit d00df5d

Browse files
committed
lesson 10 extend
1 parent 7585700 commit d00df5d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

examples/10-fold-map.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// folding a type
2+
13
const { Map, List } = require('immutable-ext')
24
const { Sum } = require('../examples/monoid')
35

@@ -11,14 +13,16 @@ const res = List.of(Sum(1), Sum(33), Sum(4))
1113
console.log(res)
1214

1315

14-
const r1 = Map({
15-
brian: 3,
16-
sara: 5
17-
})
18-
.map(Sum)
19-
.fold(Sum.empty())
16+
const r1 = Map({ brian: 3, sara: 5 })
17+
.map(Sum)
18+
.fold(Sum.empty())
19+
20+
const r11 = Map({ brian: 3, sara: 5 })
21+
22+
// run function Sum on each value, then fold
23+
.foldMap(Sum, Sum.empty())
2024

21-
console.log(r1)
25+
console.log(r1, r11)
2226

2327

2428
const r2 = List.of(1,3,45)

0 commit comments

Comments
 (0)