Skip to content

Commit e3cc089

Browse files
committed
Refactor single argument functions
1 parent 3ea2db7 commit e3cc089

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

‎JavaScript/6-promise-sequential.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@
22

33
// Emulate asynchronous calls
44

5-
const wrapAsync = (callback) => setTimeout(
5+
const wrapAsync = callback => setTimeout(
66
callback, Math.floor((Math.random() * 1000))
77
);
88

99
const isWeekend = () => !(new Date().getDay() % 6);
1010

1111
// Asynchronous functions
1212

13-
const readConfig = (name) => new Promise((resolve, reject) => {
13+
const readConfig = name => new Promise((resolve, reject) => {
1414
wrapAsync(() => {
1515
console.log('(1) config loaded');
1616
if (!isWeekend()) resolve({ name });
1717
else reject(new Error('Promises will resolve next working day'));
1818
});
1919
});
2020

21-
const doQuery = (statement) => new Promise((resolve, reject) => {
21+
const doQuery = statement => new Promise((resolve, reject) => {
2222
wrapAsync(() => {
2323
console.log('(2) SQL query executed: ' + statement);
2424
if (!isWeekend()) resolve([{ name: 'Kiev' }, { name: 'Roma' }]);
2525
else reject(new Error('Promises will resolve next working day'));
2626
});
2727
});
2828

29-
const httpGet = (url) => new Promise((resolve, reject) => {
29+
const httpGet = url => new Promise((resolve, reject) => {
3030
wrapAsync(() => {
3131
console.log('(3) Page retrieved: ' + url);
3232
if (!isWeekend()) resolve('<html>Some archaic web here</html>');
3333
else reject(new Error('Promises will resolve next working day'));
3434
});
3535
});
3636

37-
const readFile = (path) => new Promise((resolve, reject) => {
37+
const readFile = path => new Promise((resolve, reject) => {
3838
wrapAsync(() => {
3939
console.log('(4) Readme file loaded: ' + path);
4040
if (!isWeekend()) resolve('file content');
@@ -48,10 +48,10 @@ Promise.resolve()
4848
.then(readConfig.bind(null, 'myConfig'))
4949
.then(doQuery.bind(null, 'select * from cities'))
5050
.then(httpGet.bind(null, 'http://kpi.ua'))
51-
.catch((err) => console.log('Reject reason (1): ' + err.message))
51+
.catch(err => console.log('Reject reason (1): ' + err.message))
5252
.then(readFile.bind(null, 'README.md'))
53-
.catch((err) => console.log('Reject reason (2): ' + err.message))
54-
.then((data) => {
53+
.catch(err => console.log('Reject reason (2): ' + err.message))
54+
.then(data => {
5555
console.log('Done');
5656
console.dir({ data });
5757
});

‎JavaScript/7-promise-all.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22

33
// Emulate asynchronous calls
44

5-
const wrapAsync = (callback) => setTimeout(
5+
const wrapAsync = callback => setTimeout(
66
callback, Math.floor((Math.random() * 1000))
77
);
88

99
// Asynchronous functions
1010

11-
const readConfig = (name) => new Promise(resolve => {
11+
const readConfig = name => new Promise(resolve => {
1212
wrapAsync(() => {
1313
console.log('(1) config loaded: ' + name);
1414
resolve({ name });
1515
});
1616
});
1717

18-
const doQuery = (statement) => new Promise(resolve => {
18+
const doQuery = statement => new Promise(resolve => {
1919
wrapAsync(() => {
2020
console.log('(2) SQL query executed: ' + statement);
2121
resolve([ { name: 'Kiev' }, { name: 'Roma' } ]);
2222
});
2323
});
2424

25-
const httpGet = (url) => new Promise(resolve => {
25+
const httpGet = url => new Promise(resolve => {
2626
wrapAsync(() => {
2727
console.log('(3) Page retrieved: ' + url);
2828
resolve('<html>Some archaic web here</html>');
2929
});
3030
});
3131

32-
const readFile = (path) => new Promise(resolve => {
32+
const readFile = path => new Promise(resolve => {
3333
wrapAsync(() => {
3434
console.log('(4) Readme file loaded: ' + path);
3535
resolve('file content');
@@ -43,7 +43,7 @@ Promise.all([
4343
doQuery('select * from cities'),
4444
httpGet('http://kpi.ua'),
4545
readFile('README.md')
46-
]).then((data) => {
46+
]).then(data => {
4747
console.log('Done');
4848
console.dir({ data });
4949
});

‎JavaScript/8-promise-mixed.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22

33
// Emulate asynchronous calls
44

5-
const wrapAsync = (callback) => setTimeout(
5+
const wrapAsync = callback => setTimeout(
66
callback, Math.floor((Math.random() * 1000))
77
);
88

99
// Asynchronous functions
1010

11-
const readConfig = (name) => new Promise(resolve => {
11+
const readConfig = name => new Promise(resolve => {
1212
wrapAsync(() => {
1313
console.log('(1) config loaded: ' + name);
1414
resolve({ name });
1515
});
1616
});
1717

18-
const doQuery = (statement) => new Promise(resolve => {
18+
const doQuery = statement => new Promise(resolve => {
1919
wrapAsync(() => {
2020
console.log('(2) SQL query executed: ' + statement);
2121
resolve([ { name: 'Kiev' }, { name: 'Roma' } ]);
2222
});
2323
});
2424

25-
const httpGet = (url) => new Promise(resolve => {
25+
const httpGet = url => new Promise(resolve => {
2626
wrapAsync(() => {
2727
console.log('(3) Page retrieved: ' + url);
2828
resolve('<html>Some archaic web here</html>');
2929
});
3030
});
3131

32-
const readFile = (path) => new Promise(resolve => {
32+
const readFile = path => new Promise(resolve => {
3333
wrapAsync(() => {
3434
console.log('(4) Readme file loaded: ' + path);
3535
resolve('file content');
@@ -45,7 +45,7 @@ Promise.resolve()
4545
httpGet('http://kpi.ua')
4646
]))
4747
.then(readFile.bind(null, 'README.md'))
48-
.then((data) => {
48+
.then(data => {
4949
console.log('Done');
5050
console.dir({ data });
5151
});

‎JavaScript/9-events.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ const wrapAsync = fn => (...args) => setTimeout(
1111

1212
// Asynchronous functions
1313

14-
const readConfig = wrapAsync((name) => {
14+
const readConfig = wrapAsync(name => {
1515
console.log('(1) config loaded');
1616
ee.emit('config', { name });
1717
});
1818

19-
const doQuery = wrapAsync((statement) => {
19+
const doQuery = wrapAsync(statement => {
2020
console.log('(2) SQL query executed: ' + statement);
2121
ee.emit('query', [ { name: 'Kiev' }, { name: 'Roma' } ]);
2222
});
2323

24-
const httpGet = wrapAsync((url) => {
24+
const httpGet = wrapAsync(url => {
2525
console.log('(3) Page retrieved: ' + url);
2626
ee.emit('page', '<html>Some archaic web here</html>');
2727
});
2828

29-
const readFile = wrapAsync((path) => {
29+
const readFile = wrapAsync(path => {
3030
console.log('(4) Readme file loaded: ' + path);
3131
ee.emit('done', 'file content');
3232
});

‎JavaScript/g-async-await.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ const pause = () => new Promise((resolve) =>
88

99
// Asynchronous functions
1010

11-
const readConfig = async (name) => {
11+
const readConfig = async name => {
1212
await pause();
1313
console.log('(1) config loaded');
1414
return { name };
1515
}
1616

17-
const doQuery = async (statement) => {
17+
const doQuery = async statement => {
1818
await pause();
1919
console.log('(2) SQL query executed: ' + statement);
2020
return [{ name: 'Kiev' }, { name: 'Roma' }];
2121
};
2222

23-
const httpGet = async (url) => {
23+
const httpGet = async url => {
2424
await pause();
2525
console.log('(3) Page retrieved: ' + url);
2626
return '<html>Some archaic web here</html>';
2727
};
2828

29-
const readFile = async (path) => {
29+
const readFile = async path => {
3030
await pause();
3131
console.log('(4) Readme file loaded: ' + path);
3232
return 'file content';

0 commit comments

Comments
 (0)