Menu

gitpiper

collectInto javascript Code Snippet in 2024

functionarrayintermediate

Last Updated: 17 December 2024

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.
const collectInto = fn => (...args) => fn(args);
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)

javascript snippet similar to collectInto For You in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️