Skip to content

Commit 0e5d5a8

Browse files
committed
Lesson 6 - add comments and rename
1 parent de65a07 commit 0e5d5a8

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

examples/6-semigroups-examples.js renamed to examples/6-semigroups-types.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,54 @@
44
const {Map} = require('immutable-ext')
55

66

7+
// Sum container adds semigroup structure
8+
// via the 'concat' method
79
const Sum = x =>
810
({
11+
// make x accessible via 'x' prop
912
x,
1013

1114
// destructuring value for the key 'x'
12-
concat: ({x: y}) =>
13-
Sum(x + y),
15+
// equivalent to y = argument.x
16+
// Usage: Sum(n).concat(Sum(m)) //=> Sum(n+m)
17+
concat: ({x: y}) => Sum(x + y),
1418

1519
// custom getter used by console.log
16-
inspect: () => `Sum(${x})`
20+
inspect: _ => `Sum(${x})`
1721
})
1822

23+
console.log(
24+
'Sum(22).concat(Sum(33)): ',
25+
Sum(22).concat(Sum(33))
26+
)
1927

28+
29+
// All container add logical (boolean) 'concat'
2030
const All = x =>
2131
({
2232
x,
23-
concat: ({x: y}) =>
24-
All(x && y),
33+
concat: ({x: y}) => All(x && y),
2534

2635
// custom getter used by console.log
27-
inspect: () => `All(${x})`
36+
inspect: _ => `All(${x})`
2837
})
2938

39+
console.log(
40+
'All(true).concat(All(false)): ',
41+
All(true).concat(All(false))
42+
)
43+
44+
3045

3146
const First = x =>
3247
({
3348
x,
49+
3450
// throw away the arg and keep our First
3551
concat: _ => First(x),
3652

3753
// custom getter used by console.log
38-
inspect: () => `First(${x})`
54+
inspect: _ => `First(${x})`
3955
})
4056

4157

0 commit comments

Comments
 (0)