This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const f9 = pipe( | |
a => ({ status: a }), | |
a => Promise.reject('reject!'), | |
).exception(e => e && e.status == 10) ( | |
e => console.log('e 10') | |
).error( | |
e => console.log(e) | |
).nullable( | |
e => console.log('nullable~') | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isNagativeNumber = a => a < 0; | |
const f7 = pipe( | |
a => a - 10, | |
a => a + 100 | |
).exception(isNagativeNumber) ( | |
_ => console.log('중간에 빠져나옴') | |
); | |
console.log( f7(10) ); // 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const f4 = pipe( | |
a => a + 10, | |
a => asdasd123asdasd, | |
a => a + 100 // <-- 오지 않습니다. | |
).error(log); // ReferenceError: asdasd123asdasd is not defined | |
log(f4(1)); // undefined 리턴되고, error로 가서 에러 출력 | |
const f5 = pipe( | |
a => a + 10, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const f0 = pipe( | |
a => a + 10, // <--- null 온 경우 실행되지 않음 | |
a => a + 100 // <--- null 온 경우 실행되지 않음 | |
).nullable(); | |
console.log( f0(1) ); // 111 | |
console.log( f0(null) ); // null | |
const f1 = pipe( | |
a => a + 10, // <--- null 온 경우 실행되지 않음 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 동시에 users와 posts 출발 | |
const res1 = awiat concurrency({ | |
users: _=> query(...), | |
posts: _=> query(...) | |
}); | |
//{ | |
// users: [row, row, row, ...] | |
// posts: [row, row, row, ...] | |
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
some(pipe(get, isBlah), [{ ... }, { ... }, { ... }]); | |
// - 하나씩 시도 | |
// - 만일 첫 번째에서 참을 만들면 뒤에 2개는 디비 요청을 하지 않음 | |
someC(pipe(get, isBlah), [{ ... }, { ... }, { ... }]); | |
// - 동시에 3개 모두 디비 요청 | |
// - 먼저 온 결과를 통해 참을 만들면 나머지 결과를 더 기다리지 않고 다음으로 넘어감 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go([0, 0, 3000, 5000, 6000, 1000, 5000], | |
someC(a => new Promise(function (resolve) { | |
setTimeout(function() { resolve(a); }, a); | |
})), | |
b => console.log(b, '<----------- 1초 뒤')); | |
// true <----------- 1초 뒤 | |
// - 모든 값에 해당하는 함수 평가 | |
// - 1000이 가장 먼저 결과를 만들어서 1초 뒤 결과를 즉시 리턴하고, 나머지는 기다리지 않음 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go([0, 0, 3000, 5000, 6000, 1000, 5000], | |
some(a => new Promise(function (resolve) { | |
setTimeout(function() { resolve(a); }, a); | |
})), | |
b => console.log(b, '<---------- 3초 정도 뒤')); | |
// true <------ 3초 정도 뒤 | |
// - 0, 0, 3000에 해당하는 함수만 평가 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async function() { | |
const list = [1, 2, 3, 4]; | |
const result = await map(async function(val) { | |
return await add2(val); | |
}, list); | |
console.log(result, 'async/await 3'); | |
// [3, 4, 5, 6] async/await 3 | |
}) (); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async function() { | |
const list = [1, 2, 3, 4]; | |
const result = await list.map(async function(val) { | |
return await add2(val); | |
}); | |
console.log(result, 'async/await 2'); | |
// [Promise, Promise, Promise, Promise] async/await 2 | |
}) (); |