Snippet format update

To match the starter (for the migration)
This commit is contained in:
Angelos Chalaris
2019-08-13 10:29:12 +03:00
parent a5164f392a
commit 611729214a
381 changed files with 1951 additions and 1989 deletions

View File

@ -1,17 +1,20 @@
### collectInto
---
title: collectInto
tags: adapter,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.
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)
```
```