Skip to content

Instantly share code, notes, and snippets.

View indongyoo's full-sized avatar
๐ŸŽฏ
Focusing

์œ ์ธ๋™ indongyoo

๐ŸŽฏ
Focusing
View GitHub Profile
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~')
);
const isNagativeNumber = a => a < 0;
const f7 = pipe(
a => a - 10,
a => a + 100
).exception(isNagativeNumber) (
_ => console.log('์ค‘๊ฐ„์— ๋น ์ ธ๋‚˜์˜ด')
);
console.log( f7(10) ); // 100
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,
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 ์˜จ ๊ฒฝ์šฐ ์‹คํ–‰๋˜์ง€ ์•Š์Œ
// ๋™์‹œ์— users์™€ posts ์ถœ๋ฐœ
const res1 = awiat concurrency({
users: _=> query(...),
posts: _=> query(...)
});
//{
// users: [row, row, row, ...]
// posts: [row, row, row, ...]
//}
some(pipe(get, isBlah), [{ ... }, { ... }, { ... }]);
// - ํ•˜๋‚˜์”ฉ ์‹œ๋„
// - ๋งŒ์ผ ์ฒซ ๋ฒˆ์งธ์—์„œ ์ฐธ์„ ๋งŒ๋“ค๋ฉด ๋’ค์— 2๊ฐœ๋Š” ๋””๋น„ ์š”์ฒญ์„ ํ•˜์ง€ ์•Š์Œ
someC(pipe(get, isBlah), [{ ... }, { ... }, { ... }]);
// - ๋™์‹œ์— 3๊ฐœ ๋ชจ๋‘ ๋””๋น„ ์š”์ฒญ
// - ๋จผ์ € ์˜จ ๊ฒฐ๊ณผ๋ฅผ ํ†ตํ•ด ์ฐธ์„ ๋งŒ๋“ค๋ฉด ๋‚˜๋จธ์ง€ ๊ฒฐ๊ณผ๋ฅผ ๋” ๊ธฐ๋‹ค๋ฆฌ์ง€ ์•Š๊ณ  ๋‹ค์Œ์œผ๋กœ ๋„˜์–ด๊ฐ
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์ดˆ ๋’ค ๊ฒฐ๊ณผ๋ฅผ ์ฆ‰์‹œ ๋ฆฌํ„ดํ•˜๊ณ , ๋‚˜๋จธ์ง€๋Š” ๊ธฐ๋‹ค๋ฆฌ์ง€ ์•Š์Œ
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์— ํ•ด๋‹นํ•˜๋Š” ํ•จ์ˆ˜๋งŒ ํ‰๊ฐ€
(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
}) ();
(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
}) ();