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')],
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), );
GitHub: 18xx-maker/18xx-maker
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,
+ 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)))
+ 2 other calls in file
GitHub: ayush-rudani/npmBox
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
+ 5 other calls in file
GitHub: DFEAGILEDEVOPS/MTC
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 )
+ 15 other calls in file
GitHub: mvp-rockets/lib-core
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([
+ 551 other calls in file
GitHub: hakantunc/hyp-down
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))
GitHub: Morozzko/React_Blank_App
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) }
GitHub: Morozzko/React_Blank_App
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 =
+ 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)) )
+ 9 other calls in file
GitHub: zhentian-wan/ADT-demo
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(
+ 3 other calls in file
GitHub: alvaro-cuesta/aoc-js
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) {
+ 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', {
+ 19 other calls in file
GitHub: DFEAGILEDEVOPS/MTC
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
+ 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'])
+ 29 other calls in file
GitHub: calmm-js/partial.lenses
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
+ 11 other calls in file
GitHub: lcofjp/visual-serial
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) {
GitHub: com2u/SVTrain
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) =>
+ 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 }), {}
ramda.clone is the most popular function in ramda (30311 examples)