From 5342d0c3181ff362536b2f05ae428d3f6d55846b Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 13 Jan 2020 10:04:41 +0200 Subject: [PATCH] Update collectInto.md --- snippets/collectInto.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/snippets/collectInto.md b/snippets/collectInto.md index 82bee2047..93d00feec 100644 --- a/snippets/collectInto.md +++ b/snippets/collectInto.md @@ -1,20 +1,20 @@ ---- -title: collectInto -tags: adapter,function,array,intermediate ---- - +--- +title: collectInto +tags: function,array,intermediate +--- + Changes a function that accepts an array into a variadic function. -Given a function, return a closure that collects all inputs into an array-accepting function. - -```js -const collectInto = fn => (...args) => fn(args); -``` - -```js -const Pall = collectInto(Promise.all.bind(Promise)); -let p1 = Promise.resolve(1); -let p2 = Promise.resolve(2); -let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3)); -Pall(p1, p2, p3).then(console.log); // [1, 2, 3] (after about 2 seconds) -``` \ No newline at end of file +Given a function, return a closure that collects all inputs into an array-accepting function. + +```js +const collectInto = fn => (...args) => fn(args); +``` + +```js +const Pall = collectInto(Promise.all.bind(Promise)); +let p1 = Promise.resolve(1); +let p2 = Promise.resolve(2); +let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3)); +Pall(p1, p2, p3).then(console.log); // [1, 2, 3] (after about 2 seconds) +```