How to use the ramda.filter 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 amazeeio / lagoon / services / api / src / models / group.ts View on Github external
});

  if (R.isEmpty(keycloakGroups)) {
    throw new GroupNotFoundError(`Group not found: ${name}`);
  }

  // Use mutable operations to avoid running out of heap memory
  const flattenGroups = (groups, group) => {
    groups.push(R.omit(['subGroups'], group));
    const flatSubGroups = group.subGroups.reduce(flattenGroups, []);
    return groups.concat(flatSubGroups);
  };

  const groupId = R.pipe(
    R.reduce(flattenGroups, []),
    R.filter(R.propEq('name', name)),
    R.path(['0', 'id'])
  )(keycloakGroups);

  if (R.isNil(groupId)) {
    throw new GroupNotFoundError(`Group not found: ${name}`);
  }

  // @ts-ignore
  return await loadGroupById(groupId);
};
github loop-recur / FPJS-Class / part1_exercises / answers / compose / compose_exercises.js View on Github external
// Exercise 4:
// ============
// Write a function: sanitizeNames() using compose that returns a list of lowercase and underscored names: e.g: sanitizeNames(["Hello World"]) //=> ["hello_world"].

var _underscore = _.replace(/\W+/g, '_'); //<-- leave this alone and use to sanitize

var sanitizeNames = _.map(_.compose(_underscore, _.toLower, _.prop('name')));


// Bonus 1:
// ============
// Refactor availablePrices with compose.

var formatPrice = _.compose(accounting.formatMoney, _.prop('dollar_value'));
var availablePrices = _.compose(join(', '), _.map(formatPrice), _.filter(_.prop('in_stock')));

// Bonus 2:
// ============
// Refactor to pointfree. Hint: you can use _.flip()

//+ fastestCar :: [Car] -> String
var append = _.flip(_.concat);
var fastestCar = _.compose(append(' is the fastest'),
                           _.prop('name'),
                           _.last,
                           _.sortBy(_.prop('horsepower')));

module.exports = { CARS: CARS,
                   isLastInStock: isLastInStock,
                   nameOfFirstCar: nameOfFirstCar,
                   fastestCar: fastestCar,
github danielwii / asuna-node-server / src / modules / core / db / db.helper.ts View on Github external
info: info ? info[column.propertyName] : undefined,
        },
      })),
      R.filter((column: ColumnMetadata) => !R.path([column.propertyName, 'ignore'])(info)),
    )(repository.metadata.nonVirtualColumns);

    const manyToOneRelations = R.compose(
      R.map((relation: RelationMetadata) => ({
        name: relation.propertyName,
        config: {
          selectable: DBHelper.extractSelectableByRelation(relation, opts),
          type: R.is(String, relation.type) ? relation.type : (relation.type as Function).name,
          info: info ? info[relation.propertyName] : undefined,
        },
      })),
      R.filter((column: ColumnMetadata) => !R.path([column.propertyName, 'ignore'])(info)),
    )(repository.metadata.manyToOneRelations);

    const manyToManyRelations = R.compose(
      R.map(
        (relation: RelationMetadata): ColumnSchema => ({
          name: relation.propertyName,
          config: {
            selectable: DBHelper.extractSelectableByRelation(relation, opts),
            type: R.is(String, relation.type) ? relation.type : (relation.type as Function).name,
            // nullable  : relation.isNullable,
            many: true,
            info: info ? info[relation.propertyName] : undefined,
          },
        }),
      ),
      R.filter(R.prop('isPrimary')),
github jdiaz5513 / capnp-ts / packages / capnpc-ts / src / json / index.ts View on Github external
const { cgr, fd } = ctx;
    const {
      dataWordCount,
      discriminantCount,
      discriminantOffset,
      fields,
      pointerCount
    } = node.struct;
    const hasUnnamedUnion = discriminantCount !== 0;
    const nestedNodes = R.filter(
      n => n.const === undefined,
      R.map(lookupNode(ctx), node.nestedNodes || [])
    );
    const concreteLists = R.filter(Field.needsConcreteListClass, fields);
    const consts = R.filter(
      n => n.scopeId === node.id && n.const !== undefined,
      cgr.nodes
    );
    const groups = R.filter(
      n => n.scopeId === node.id && n.struct !== undefined && n.struct.isGroup,
      cgr.nodes
    );

    /* tslint:disable-next-line:no-use-before-declare */
    R.forEach(generateNode(ctx), nestedNodes);

    if (hasUnnamedUnion) generateUnnamedUnionEnum(ctx, node);

    const Class = Node.getFullClassName(node);
    const Name = Node.getDisplayNamePrefix(node);
github tengen-io / web-client / src / components / game / square.jsx View on Github external
// Style
import style from '../../stylesheets/square.scss';

// Move these into game config
const numberOfSquares = 361;
const corners = [0,18,342,360];
const guides = [60,66,72,174,180,186,288,294,300];

const allSquares = Array.from(
    new Array(numberOfSquares), (val, index) => index
);

const sideTop        = R.filter( (i) =>   0 < i && i <  18,   allSquares )
const sideBottom     = R.filter( (i) => 342 < i && i < 360,   allSquares )
const sideLeft       = R.filter( (i) => i % 19 === 0,         allSquares )
const sideRight      = R.filter( (i) => i % 19 === 18,        allSquares )

function createPositionClass( position ) {
    if ( position === 0 )                   { return "corner top-left" };
    if ( position === 18 )                  { return "corner top-right" };
    if ( position === 342 )                 { return "corner bottom-left" };
    if ( position === 360 )                 { return "corner bottom-right" };
    if ( R.contains(position, sideTop) )    { return "side side-top" };
    if ( R.contains(position, sideBottom) ) { return "side side-bottom" };
    if ( R.contains(position, sideLeft) )   { return "side side-left" };
    if ( R.contains(position, sideRight) )  { return "side side-right" };
    if ( R.contains(position, guides) )     { return "central guide-square" };
    return "central";
}
github jdiaz5513 / capnp-ts / packages / capnpc-ts / src / json / index.ts View on Github external
if (node.struct === undefined) throw new Error("wat");

    const { cgr, fd } = ctx;
    const {
      dataWordCount,
      discriminantCount,
      discriminantOffset,
      fields,
      pointerCount
    } = node.struct;
    const hasUnnamedUnion = discriminantCount !== 0;
    const nestedNodes = R.filter(
      n => n.const === undefined,
      R.map(lookupNode(ctx), node.nestedNodes || [])
    );
    const concreteLists = R.filter(Field.needsConcreteListClass, fields);
    const consts = R.filter(
      n => n.scopeId === node.id && n.const !== undefined,
      cgr.nodes
    );
    const groups = R.filter(
      n => n.scopeId === node.id && n.struct !== undefined && n.struct.isGroup,
      cgr.nodes
    );

    /* tslint:disable-next-line:no-use-before-declare */
    R.forEach(generateNode(ctx), nestedNodes);

    if (hasUnnamedUnion) generateUnnamedUnionEnum(ctx, node);

    const Class = Node.getFullClassName(node);
    const Name = Node.getDisplayNamePrefix(node);
github dennisreimann / uiengine / packages / core / src / builder.js View on Github external
async function generatePagesWithTemplate (state, template) {
  debug3(state, `Builder.generatePagesWithTemplate(${template}):start`)

  const affectedPages = R.filter(page => [page.template, page.fragment].includes(template), state.pages)
  const pageIds = Object.keys(affectedPages)
  const build = R.partial(generatePageWithTemplate, [state])
  const builds = R.map(build, pageIds)

  await Promise.all(builds)

  debug3(state, `Builder.generatePagesWithTemplate(${template}):end`)
}
github envkey / envkey-app / envkey-react / src / lib / env / inheritance.js View on Github external
productionInheritanceOverrides = (envsWithMeta, subEnvId) => R.pipe(
    R.propOr({}, "production"),

    R.filter((envsWithMetaCell)=> envsWithMetaCell && envsWithMetaCell.inherits && envsWithMetaCell.locked),

    R.mapObjIndexed(({inherits}, entryKey)=> {
      const metaSubEnv = R.path([
        "productionMetaOnly",
        "@@__sub__",
        subEnvId
      ], envsWithMeta)

      if (metaSubEnv &&
          metaSubEnv[entryKey] &&
          metaSubEnv[entryKey].hasVal){
        return undefined
      }

      return inheritedVal({inherits, entryKey, envsWithMeta})
    }),