ramda.js

How to remove unnecessary casting with Ramda and Typescript

…衆ロ難τιáo~ 提交于 2021-01-29 08:57:52
问题 Consider const darkPalette = [ '#255dbd', '#2c6bd7', '#5386e2', '#7ea5e9', '#49bbdb', '#56d6f9', '#89e2fa', '#aaeafc', '#00a690', '#10bda4', '#6ad8c8', '#9de4da', '#9dc53b', '#bae050', '#dcf0a3', '#eaf6c8', ] const transposePalette = compose(flatten, transpose, splitEvery(4)) const transposedDarkPalette = transposePalette(darkPalette) When i receive the result of transposedDarkPalette the compiler complains: Types of property 'color' are incompatible. Type '{}[]' is not assignable to type

How to compose an ascending/descending sort in Ramda

本秂侑毒 提交于 2021-01-28 08:32:57
问题 I have a React component with a sorting headers table. This code works as planned: //definitions and imports... const [sort, setSort] = useState({column: 'rank', direction: 'ascending', isNumber: true}); const handleSort = (column, isNumber = false) => () => { let direction = (sort.column !== column) ? 'ascending' : (sort.direction === 'ascending' ? 'descending' : 'ascending'); setSort({column, direction, isNumber}); }; const getSortedData = (data) => { let sorted = R.sortBy( R.compose( sort

Sorting using nested field in ramda.js

不问归期 提交于 2020-12-12 08:50:31
问题 In the documentation of sortBy, it says we can use R.prop to sort an object by it's field. But if I have to sort by a nested field, it does not work. For example R.prop('id.number') does not work. var items = [{id:3},{id:1},{id:2}]; var sorter = R.sortBy(R.prop('id')); sorter(items) works fine. But if I have a nested structure var items = [{id:{number:3}},{id:{number:1}},{id:{number:2}}]; var sorter = R.sortBy(R.prop('id.number')); sorter(items) returns me an empty list. I guess there is a

Ramda: find object key by nested key value

笑着哭i 提交于 2020-07-22 21:50:23
问题 Is there any function in ramda how can I find key by nested key value? I found a way how to find an object in array but that doesn't help. I need something like this: const obj = { addCompany: { mutationId: '1' }, addUser: { mutationId: '2' }, addCompany: { mutationId: '3' } } const findByMutationId = R.??? findByMutationId('2', obj) // returns addUser 回答1: find combined with propEq and keys should work const obj = { addCompany: { mutationId: '1' }, addUser: { mutationId: '2' }, addCompany2:

Ramda recursive merge based on keys' match

拈花ヽ惹草 提交于 2020-05-22 09:40:52
问题 I have two lists of nodes, who shaped like so: interface TreeNode { data: { name: string, sharedProp: boolean, oldProp: boolean }, children: TreeNode[], parents: TreeNode[], thereAreSomeShallowProps: any, } The full dataset would be an array of TreeNode What I'd like is to have a function that I can traverse down this tree, merging changes in a changes tree into the base tree. Some of the feature it'd need: Match the values of a specified key (in this case support multilevel keys), and merge

How to aggregate and merge objects based on multiple properties?

穿精又带淫゛_ 提交于 2020-03-06 09:29:05
问题 I need your support to make a groupby in Ramda. I have a data and I require: Sort the data by its type of service Separate those that are the same product code Make the groupby of duration Make the merge of all the data Data: [{ 'id': '1', 'serviceType': { 'description': 'GE' }, 'productCode': 'codeTwo', 'duration': { 'months': 24 }, }, { 'id': '2', 'serviceType': { 'description': 'GE' }, 'productCode': 'codeOne', 'duration': { 'months': 12 } }, { 'id': '3', 'serviceType': { 'description':