Skip to content

Commit c70cff3

Browse files
committed
Update examples
1 parent d609782 commit c70cff3

File tree

12 files changed

+29
-6
lines changed

12 files changed

+29
-6
lines changed

JavaScript/1-context.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const hash = () => {
1111
};
1212
};
1313

14+
// Usage
15+
1416
const h1 = hash();
1517
h1('name', 'Marcus');
1618
h1('city', 'Roma');

JavaScript/2-chain.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const hash = () => {
1212
return data;
1313
};
1414

15+
// Usage
16+
1517
console.dir(
1618
hash()
1719
.add('name', 'Marcus')

JavaScript/3-closure.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const add = x => y => {
88

99
// const add = x => y => x + y;
1010

11-
const res = add(3)(6);
11+
// Usage
1212

13+
const res = add(3)(6);
1314
console.log(res);

JavaScript/4-closure-recursive.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ const add = x => y => {
88

99
// const add = x => y => add(x + y);
1010

11+
// Usage
12+
1113
const a1 = add(5);
1214
const a2 = a1(2);
1315
const a3 = a2(3);
1416
const a4 = a1(1);
1517
const a5 = a2(10);
16-
1718
console.log(a1, a2, a3, a4, a5);
1819

1920
const res = add(1)(4)(8)(8);
20-
2121
console.log(res);

JavaScript/5-logger.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ logger.colors = {
1414
info: '\x1b[1;37m'
1515
};
1616

17+
// Usage
18+
1719
const warning = logger('warning');
1820
const error = logger('error');
1921
const debug = logger('debug');

JavaScript/6-functor.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ const add = x => {
1010
return f;
1111
};
1212

13+
// Usage
14+
1315
const a1 = add(5);
1416
const a2 = a1(2);
1517
const a3 = a2(3);
1618
const a4 = a1(1);
1719
const a5 = a2(10);
20+
console.log('a3 sum is:');
21+
a3.map(console.log);
1822

19-
const print = x => console.log(x);
20-
[a3, a4, a5].map(x => typeof(x)).map(print);
23+
console.log('\nAll functors:');
24+
[a1, a2, a3, a4, a5].map(fn => fn.map(console.log));

JavaScript/7-functor-short.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ const add = x => {
66
return f;
77
};
88

9+
// Usage
10+
911
add(2)(7)(1).map(console.log);

JavaScript/8-adder.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ const adder = (a) => {
66
return { add, value };
77
};
88

9+
// Usage
10+
911
const v = adder(3).add(-9).add(12).value();
1012
console.log(v);

JavaScript/9-adder-on.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ const adder = (a) => {
1919
return Object.assign(obj, { add, value, on });
2020
};
2121

22+
// Usage
23+
2224
const a = adder(3)
23-
.add(-9)
2425
.on('zero', () => console.log('Less than zero'))
26+
.add(-9)
2527
.add(12)
2628
.add(5)
2729
.value();

JavaScript/a-adder.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ const adder = (a) => {
1212
return obj;
1313
};
1414

15+
// Usage
16+
1517
const v = adder(3).add(-9).add(12).value();
1618
console.log(v);

0 commit comments

Comments
 (0)