moltres-utils
Version:
Utils for Moltres apps
58 lines (52 loc) • 1.39 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _curryN = _interopRequireDefault(require("../data/curryN"));
var _defn = _interopRequireDefault(require("../data/defn"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Walk using the given walkee and iteratee functions.
*
* @func
* @since v0.1.0
* @category data
* @sig
* @param {Function} walkee The function responsible for returning the next value in the walk
* @param {Function} iteratee The iterator function.
* @returns {*} The final value returned by the walk
* @example
*
* const depthFirstWalkee = (value, iteratee, recur) => {
* if (isObject(value)) {
* forEachObjIndexed((child) => {
* recur(child, iteratee)
* }, value)
* }
* iteratee(value, data)
* }
* let result = []
* walk(
* depthFirstWalkee,
* (value) => result.push(value),
* {
* a: {
* b: 'b'
* }
* }
* )
* console.log(result)
* //=> [
* 'b',
* { b: 'b' },
* { a: { b: 'b' } }
* ]
*/
const walk = (0, _curryN.default)(3, (0, _defn.default)('walk', (walkee, iteratee, ...args) => {
const walker = (...pass) => walkee(...pass, walker);
return walkee(...args, iteratee, walker);
}));
var _default = walk;
exports.default = _default;
//# sourceMappingURL=walk.js.map
;