UNPKG

f-utility

Version:

functional utilities

54 lines (49 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.delegateFastTertiary = exports.delegateFastBinary = exports.__willDelegate = undefined; exports.__delegateFastBinary = __delegateFastBinary; exports.__delegateFastTertiary = __delegateFastTertiary; var _katsuCurry = require("katsu-curry"); var has = function has(x, y) { return !!y[x]; }; var isArray = Array.isArray; var __willDelegate = exports.__willDelegate = function __willDelegate(method, functor) { return has(method, functor) && !isArray(functor); }; /** * functor-last curried goodness * @method willDelegate * @param {string} method * @param {*} functor * @returns {boolean} should we delegate? * @private */ // const willDelegate = curry(__willDelegate) function __delegateFastBinary(method, fast, fn, functor) { return __willDelegate(method, functor) ? functor[method](fn) : fast(functor, fn); } /** * functor-last curried goodness * @method delegateFastBinary * @param {function} fn * @param {Array} functor * @returns {Array} mapped iterable * @private */ var delegateFastBinary = exports.delegateFastBinary = (0, _katsuCurry.curry)(__delegateFastBinary); function __delegateFastTertiary(method, fast, fn, initial, functor) { return __willDelegate(method, functor) ? functor[method](fn, initial) : fast(functor, fn, initial); } /** * functor-last curried goodness * @method delegateFastTertiary * @param {function} fn * @param {*} initial * @param {Array} functor * @returns {Array} mapped iterable * @private */ var delegateFastTertiary = exports.delegateFastTertiary = (0, _katsuCurry.curry)(__delegateFastTertiary);