How to use the compose function from ramda

Find comprehensive JavaScript ramda.compose code examples handpicked from public code repositorys.

18
19
20
21
22
23
24
25
26
27
28
29
  pathIsString(['recipients', 'to']),
  pathIsString(['recipients', 'condition'])
);


const propValueToSingletonArray = (propName) =>
  R.compose(R.of, R.prop(propName));


const getRecipientList = R.cond([
  [R.has('registrationTokens'), R.prop('registrationTokens')],
  [R.has('to'), propValueToSingletonArray('to')],
fork icon117
star icon518
watch icon0

19
20
21
22
23
24
25
26
27
28
29
30
31


const inGroup = ctx => ctx.chat?.type.endsWith('group');


const capturingGroups = R.tail;


const toUsername = R.compose(
	capturingGroups,
	R.match(/^(?:@|(?:https?:\/\/)?(?:t\.me|telegram\.(?:me|dog))\/)(\w+)/i),
);

fork icon162
star icon430
watch icon0

214
215
216
217
218
219
220
221
222
223
}, gutil.compileCompanies(game) || []);

// "quantity" of 0 mean remove the token entirely from the array
// "quantity of "∞" means we put the special value of 0 in for dups
// otherwise, "quantity" is the number of dups
let tokens = R.compose(
  R.map((extra) => {
    btok.token.push({
      dups: extra.quantity === "∞" ? 0 : extra.quantity || 1,
      flip: true,
fork icon52
star icon51
watch icon0

+ 4 other calls in file

13
14
15
16
17
18
19
20
21
22
23
24
const { construct } = require('../../util/util');
const Option = require('../../util/option');
const Problem = require('../../util/problem');


// It removes prefix from all the key of an object
const removePrefix = curry((prefix, obj) => compose(reduce((acc, key) => assoc(key.replace(prefix, ''), obj[key], acc), {}), keys)(obj));


const pickFrameFields = (frame, obj) => compose(
  removePrefix(`${frame.def.from}!`),
  pickBy(compose(startsWith(`${frame.def.from}!`), nthArg(1)))
fork icon49
star icon43
watch icon9

+ 2 other calls in file

126
127
128
129
130
131
132
133
134
135
136
137
 *  Diffrence between Compose and Pipe is " result of compose is not
 *  automatically curried while that of pipe is and the direction of functions executed in" .
 */


const classyGreeting = (firstName, lastName) => "The name's " + lastName + ", " + firstName + " " + lastName
const yellGreeting = R.compose(R.toUpper, classyGreeting);
yellGreeting('James', 'Bond');


/*
 * "THE NAME'S BOND, JAMES BOND"  <= final result
fork icon19
star icon15
watch icon0

+ 5 other calls in file

85
86
87
88
89
90
91
92
93
94
/**
 * Return a function that takes the keys from an object joins them together into a list
 * of sql parameter identifiers.
 * @return {function()}
 */
const createParamIdentifiers = R.compose(
  R.join(' , '),
  R.map(paramName),
  R.keys
)
fork icon14
star icon12
watch icon11

+ 15 other calls in file

18
19
20
21
22
23
24
25
26
27
28
29
30
			[R.T, mapValueAndRules(value)]
		])(rules);
	}, keys);
});


const generateValidationSet = (data, rules) => R.compose(R.flatten, mapValueAndRules)(data, rules);


const validationError = (errors) => Result.Error(new ApiError(errors, 'Validation Error', HTTP_CONSTANT.BAD_REQUEST));


const formResult = (errors) => R.cond([
fork icon4
star icon2
watch icon2

+ 551 other calls in file

74
75
76
77
78
79
80
81
82
83
}
if (data.status != 200) {
  console.log(`status:${data.status}`, data);
}
var images
  = R.compose(
      R.join('\n'),
      R.reverse(),
      R.map(o => `![](${o.link})`),
      R.filter(e => dateInBetween(new Date(e.datetime*1000), beg, end))
fork icon0
star icon6
watch icon0

34
35
36
37
38
39
40
41
42
43
44
module.exports = path => config => {
  const resolved = resolveFromRootOrNodeModules(path)
  !resolved && error(`Could not load StyleLint configuration '${path}' relative to your project root nor node_modules'`)


  const transforms = map(fn => fn(resolved), [addStyleLintPluginToPostCSSLoaders, addStylelintCustomProcessorLoader])
  const transform = compose(...transforms)


  return transform(config)
}
fork icon2
star icon5
watch icon0

6
7
8
9
10
11
12
13
14
15
const [middleware, transforms] = type(gathered) === 'Array' ? partition(isMiddleware, gathered) : [false, gathered]

const padded = insertAll(1, transforms, [identity, identity])
const newMiddlewares = middleware && intersperse(middleware, padded)
const normalizedArray = flatten(newMiddlewares || padded)
const transform = compose(...normalizedArray)

const resolved = require.resolve(path)
const config = require(resolved)
require.cache[resolved].exports =
fork icon2
star icon5
watch icon0

+ 2 other calls in file

43
44
45
46
47
48
49
50
51
52
53
    [R.T, mergeString]
  ])
)


// fromObject :: Object -> Link
const fromObject = R.compose(
  concat(defaults),
  R.pick(R.keys(defaults))
)

fork icon0
star icon4
watch icon0

+ 9 other calls in file

53
54
55
56
57
58
59
60
61
62
/*
// Using Ramda to implememnt the same logic
const {compose, map, propOr, when, propEq, mergeLeft} = require('ramda');

const markAsSelected = (id) => when(propEq('id', id), mergeLeft({selected: true}))
const over = (key, fn) => compose(map(fn), propOr([], key));

const selectCard2 = (id) => over('cards', markAsSelected(id))

console.log(
fork icon0
star icon1
watch icon0

+ 3 other calls in file

36
37
38
39
40
41
42
43
44
45
46
47
      )(i, 1, array),
    ),
  )(array)
}


const applyN = R.compose(R.reduceRight(R.compose, R.identity), R.repeat)


const gcd = (a, b) => {
  while (a !== b) {
    if (a > b) {
fork icon0
star icon1
watch icon0

+ 4 other calls in file

34
35
36
37
38
39
40
41
42
43
// View

const viewCounter = R.curry((actions, [id, model]) =>
  counter.view({
    actions: R.compose(actions, Action.Modify(id)),
    remove: R.compose(actions, R.always(Action.Remove(id))),
  }, model))

const addBtn = (actions) =>
  h('button.add', {
fork icon91
star icon0
watch icon2

+ 19 other calls in file

96
97
98
99
100
101
102
103
104
105
/**
 * Return a function that takes the keys from each object in an array and joins them
 * together into a list of sql parameter identifiers with specific IDs.
 * @type {Function}
 */
const createMultipleParamIdentifiers = (data) => data.map((d, idx) => R.compose(
  R.join(' , '),
  // @ts-ignore
  R.map(paramNameWithIdx(idx)),
  R.keys
fork icon14
star icon12
watch icon11

+ 15 other calls in file

16
17
18
19
20
21
22
23
24
25
const getUserHeader = R.compose(
  token => `Authorization: Basic ${token}`,
  user => Buffer.from(user).toString('base64')
);

const updateHeaderWithUser = R.compose(
  R.unnest,
  R.adjust(0, getUserHeader),
  R.values,
  R.pick(['user', 'header'])
fork icon303
star icon0
watch icon2

+ 29 other calls in file

43
44
45
46
47
48
49
50
51
52
const l_1 = R.lensIndex(1)
const l_50 = R.lensIndex(50)
const l_x = R.lensProp('x')
const l_y = R.lensProp('y')
const l_z = R.lensProp('z')
const l_0_x_0_y = R.compose(
  l_0,
  l_x,
  l_0,
  l_y
fork icon41
star icon901
watch icon29

+ 11 other calls in file

219
220
221
222
223
224
225
226
227
228
    if (v.length < 3) return v;
    else {
      return R.splitEvery(2)(v);
    }
  });
  const s = R.compose(R.map(R.curry(parseInt)(R.__,16)), R.flatten, m, R.split(' '))(str);
  return Buffer.from(s);
}
// display中间件
function display(buf, devObj, next) {
fork icon19
star icon47
watch icon9

116
117
118
119
120
121
122
123
124
125
126
127
128
129
const findPublicKeyFromKid = (publicKey) => (kid) =>
  find(isTheRightKid(kid))(publicKey)


const getKid = path(['header', 'kid'])


const decode = compose(curryN(2), flip)(jwt.decode)


const getUserFromPublicKey = (token) => compose(makeUser, verify(token))


const getUserFromJWK = (token) => (jwk) =>
fork icon12
star icon1
watch icon0

+ 5 other calls in file

38
39
40
41
42
43
44
45
46
47

// Merge custom actions with built-in actions
actions = { ...builtinActions, ...actions }

// Setup schemas object from type defs
const schemas = R.compose(R.indexBy(R.prop('id')), R.map(schema))(typeDefs)

const pluralTypes = Object.keys(schemas).reduce(
  (plurals, type) => ({ ...plurals, [schemas[type].plural]: type }),
  {}
fork icon2
star icon10
watch icon0

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)