File tree Expand file tree Collapse file tree 1 file changed +23
-7
lines changed Expand file tree Collapse file tree 1 file changed +23
-7
lines changed Original file line number Diff line number Diff line change 44const { Map} = require ( 'immutable-ext' )
55
66
7+ // Sum container adds semigroup structure
8+ // via the 'concat' method
79const 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'
2030const 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
3146const 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
You can’t perform that action at this time.
0 commit comments