CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
spread.js29 linesDownload Raw Back to helpers
1'use strict';2 3/**4 * Syntactic sugar for invoking a function and expanding an array for arguments.5 *6 * Common use case would be to use `Function.prototype.apply`.7 *8 *  ```js9 *  function f(x, y, z) {}10 *  const args = [1, 2, 3];11 *  f.apply(null, args);12 *  ```13 *14 * With `spread` this example can be re-written.15 *16 *  ```js17 *  spread(function(x, y, z) {})([1, 2, 3]);18 *  ```19 *20 * @param {Function} callback21 *22 * @returns {Function}23 */24export default function spread(callback) {25  return function wrap(arr) {26    return callback.apply(null, arr);27  };28}29