How to use the ramda.reduce function in ramda

To help you get started, we’ve selected a few ramda examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / ramda_v0.x.x / flow_v0.104.x- / test_ramda_v0.x.x_list.js View on Github external
const pl1: Array = _.pluck(0)([[1, 2], [3, 4]]);

  const rxs: Array = _.range(1, 10);

  const remxs: Array = _.remove(0, 2, ss);
  const remxs1: Array = _.remove(0, 2)(ss);
  const remxs2: Array = _.remove(0)(2)(ss);
  const remxs3: Array = _.remove(0)(2, ss);

  const ys4: Array = _.repeat("1", 10);
  const ys5: Array = _.repeat(1, 10);

  // reduce
  const redxs: number = reduce(_.add, 10, ns);
  const redxs1: string = reduce(_.concat, "", ss);
  const redxs2: Array = reduce(_.concat, [])(_.map(x => [x], ss));
  // Example used in docs: http://ramdajs.com/docs/#reduce
  const redxs4: number = reduce(subtract, 0, [1, 2, 3, 4]);
  // Using accumulator type that differs from the element type (A and B).
  const redxs5: number = reduce((acc, s) => acc + parseInt(s), 0, [
    "1",
    "2",
    "3"
  ]);

  const redux6a: number = reduce((acc, s) => _.reduced(acc), 0, ns)
  const redux6b: number = reduce((acc: number, s: number) => _.reduced(acc), 0, ns)
  const redxs7: number = reduce(
    (acc, s) => acc < 4 ? acc + parseInt(s) : _.reduced(acc),
    0,
    ["1", "2", "3"]
  );
github calvinlfer / skull-island / lib / kong / entities / consumers.js View on Github external
async function cleanConsumerWithCredentials(consumerNameOrId) {
        const plugins = await reduce(async (acc, nextPlugin) => {
            const pluginData = await consumerDetails(consumerNameOrId, nextPlugin);
            const pluginObject = assoc(nextPlugin, pluginData, {});
            // async-await functions return promises, so the acc from the previous round is in a Promise context
            return mergeDeepLeft(pluginObject, await acc);
        }, {}, authPlugins);

        const pluginsDataWithoutBasicAuth = dissoc('basic-auth', plugins);
        const result = authPlugins
            .filter(pluginName => pluginName !== 'basic-auth')
            .filter(pluginName => pluginsDataWithoutBasicAuth[pluginName].length > 0)
            .map(pluginName => {
                const credentialList = pluginsDataWithoutBasicAuth[pluginName];
                return {pluginName, credentialList};
            })
            .map(({pluginName, credentialList}) =>
                Promise.all(
github iamstarkov / generator-babel / generators / app / index.js View on Github external
/* eslint-disable func-names,vars-on-top */

var yeoman = require('yeoman-generator');
var R = require('ramda');
var splitKeywords = require('split-keywords');
var sortedObject = require('sorted-object');
var depsObject = require('deps-object');
var mapPrefixPreset = require('./map-babel').mapPrefixPreset;
var mapPrefixPlugin = require('./map-babel').mapPrefixPlugin;
var stringify = require('./json-fp').stringify;
var parse = require('./json-fp').parse;

// concatAll :: [Array] -> Array
var concatAll = R.reduce(R.concat, []);

module.exports = yeoman.Base.extend({
  constructor: function () {
    yeoman.Base.apply(this, arguments);
    this.argument('presets', { type: Array, required: false,
      desc: 'Presets’ list: "yo babel es2015 es2016"\n'
    });
    this.option('plugins', { type: String, required: false, alias: 'p',
      desc: 'Plugins list: "yo babel -p add-module-exports"'
    });

    // helpers
    this.saveDepsToPkg = function (deps) {
      var pkg = this.fs.readJSON(this.destinationPath('package.json'), {});
      var currentDeps = pkg.devDependencies || {};
      var mergedDeps = R.merge(currentDeps, deps);
github victorfeijo / automata / src / core / RegularExpression.js View on Github external
const nextTransitions = reduce((acc, stateComp) => {
    const composition = reduce((acc, node) => (
              [...acc, ...flatten(upMove(node))]
        ), [], stateComp.composition);

    const existentComp = findByComposition(createdStates, composition);
    if (existentComp) {
      createdStates = updateNextTransitions(createdStates, stateComp.state, existentComp.state);
      return acc;
    }

    return union(acc, [{
      state: stateComp.state,
      transitions: createCompTransitions(stateComp.state, composition, stateList),
      composedBy: composition
    }]);
  }, [], [toCreate[0]]);
github raine / ramda-destruct / src / index.js View on Github external
pipe((ramda, messages, code) =>
         reduce(handleEslintMessage(ramda), code, messages),
       replace(/\b__toString__\b/g, 'toString'));
github DXY-F2E / api-mocker / dsl-core / src / compiler.js View on Github external
const mapKey = R.curry((fn, obj) => {
  return R.reduce(function (result, item) {
    const key = R.head(item)
    const value = R.last(item)
    result[fn(key)] = value
    return result
  }, {}, R.toPairs(obj))
})
github amazeeio / lagoon / services / api / src / dao.js View on Github external
const inClauseOr = conds =>
  R.compose(
    R.reduce((ret, str) => {
      if (ret === '') {
        return str;
      }
      return `${ret} OR ${str}`;
    }, ''),
    R.map(([field, values]) => inClause(field, values)),
  )(conds);
github ccorcos / elmish / v11 / elmish.js View on Github external
export const lensQuery = (path) => {
  if (isString(path)) {
    return R.lensProp(path)
    } else if (isNumber(path)) {
    return R.lensIndex(path)
  } else if (isObject(path)) {
    return lensWhereEq(path)
  } else if (isArray(path)) {
    return R.reduce(
      (l, p) => R.compose(l, lensQuery(p)),
      lensIdentity,
      path
    )
  }
}
github 25th-floor / revalidation / src / Revalidation.js View on Github external
const runUpdates = (updateFns, state, type, enhancedProps) => reduce((updatedState, updateFn) =>
  updateFn(updatedState, type, enhancedProps), state, updateFns)
github harrysolovay / rescripts / packages / rescripts / use-babel-config / index.js View on Github external
const useConfigFile = (options, config) =>
  reduce(
    (stage, key) => assocPath(['options', key], options[key], stage),
    clearDefaults(config),
    keys(options),
  )