## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• Jan 31 2019 22:17
CrossEye commented #2779
• Jan 31 2019 21:04
ArturAralin commented #2779
• Jan 31 2019 20:08
CrossEye commented #2779
• Jan 31 2019 18:56
buzzdecafe commented #2631
• Jan 31 2019 18:09
ArturAralin commented #2779
• Jan 31 2019 16:18
CrossEye commented #2779
• Jan 31 2019 16:10
CrossEye commented #2631
• Jan 31 2019 16:06
CrossEye commented #2777
• Jan 31 2019 14:44
ArturAralin opened #2779
• Jan 31 2019 07:39
inferusvv commented #2631
• Jan 31 2019 03:07
sespinozj commented #2771
• Jan 31 2019 02:33
• Jan 31 2019 02:26
JeffreyChan commented #2777
• Jan 30 2019 14:30
CrossEye closed #2777
• Jan 30 2019 12:13
• Jan 30 2019 01:42
JeffreyChan commented #2777
• Jan 29 2019 21:06
• Jan 29 2019 16:28
CrossEye commented #2777
• Jan 29 2019 15:50
mbostock commented #2772
• Jan 29 2019 15:48
CrossEye commented #2772
Ben Briggs
@ben-eb
Exactly. That stuff is where pure functions really shine
One way to attack it would be to position Ramda as a DSL for data manipulation, and show how it can make weird imperative functions disappear into readable pipelines.
Ben Briggs
@ben-eb
I've introduced ramda to only a couple people, our main is lodash/fp right now. I'd like to change that of course :)
Both times I've taken some anonymous lambda and wrapped a ramda function around it, then progressively refactor it until it's fully declarative
const f = when(x => x === 2, x => x + 1);
const f = when(eq(2), x => x + 1);
const f = when(eq(2), inc);
for instance
But both ramda & lodash offer good stories for data manipulation
true
Ben Briggs
@ben-eb
Ohh sorry it's equals isn't it. lodash is eq :D
groupBy is one of my favorites in that it does exactly what it sounds like, it's not trivial (though not too complicated either), and it is often really helpful
Ben Briggs
@ben-eb
I'm not sure I have a favourite ramda function! What is unique about it for me is that it's a large api surface which I have used a majority of, not like a lot of libraries where you need only a handful of things
I just mean it's a good one for demonstrating value
Ben Briggs
@ben-eb
Oh I know. It's reject because of the ergonomics of it - filter(x => x !== 'foo') => reject(x => x === 'foo') - same goes for complement. Too many times writing two predicates instead of one plus complement(one)
Also, map is nice in that it works on Objects and returns the same typeclass as it receives.
Ben Briggs
@ben-eb
I think I remember ruby had the same DX
Yup, ruby has select and reject. I really liked it at the time
map is also nice - lodash has mapValues which I like less
Pierre-Antoine Mills
@millsp
what do you guys think of this? https://github.com/selfrefactor/rambda
Pierre-Antoine Mills
@millsp
the project owner claims overall 70% better performance compared to ramda... not sure how the tests are done anyway, and it does not seem to handle placeholders either
Gezim Hoxha
Trying to see if this can be done more simply:
const filtersFromUniqueIds = (items: SelectedRecipeFilter[], ids: string[]) => {
return items.filter(item => includes(item.uniqueId, ids));
};
Ben Briggs
@ben-eb
@HappyGezim_twitter R.propSatisfies ?
Twizzes
@Twizzes
@HappyGezim_twitter I I couldn't really think of a way to make it simpler, per se. But you can make it more modular(?) - I'm not too sure this is even true. I guess looking at this might spark some ideas for you, though:
const recipes = [{ uniqueId: 5 }, { uniqueId: 2 }, { uniqueId: 10 }];
const ids = [2, 5, 6, 1];

const _includes = keepers => item => R.includes(item, keepers);
const keepIds = _includes(ids);

const res = recipes.filter(R.compose(keepIds, R.prop("uniqueId")));

console.log(JSON.stringify(res));
// => [{"uniqueId":5},{"uniqueId":2}]
Ben Briggs
@ben-eb
@Twizzes Untested but could be shortened :)
const includedIn = flip(includes);

const res = filter(propSatisfies(includedIn(ids), 'uniqueId')) (recipes)
Kevin Thompson
@kthompson
im trying to make a method to convert a list into a map by id with rambda, i have the follow following but its not working as expected:
const assignById = converge(call, [
flip(assoc),
prop('id')
]);

assignById({id: 'abc', taco: 'time'}, {}) // => {abc: {id: 'abc', taco: 'time'} }
Kevin Thompson
@kthompson
i think this will work for now
const toMap = R.pipe(
R.groupBy(R.prop('id')),
)
converge sets its arity based on the highest arity of the branch functions
Kevin Thompson
@kthompson
yea i was reading that but still couldnt really figure it out
Since assoc has an arity of 3 it will take all 3 arguments before passing the results to call
if you need to partially apply a function in converge you can either do it manually (x) => flip(assoc)(x) or use a helper function like arity
Kevin Thompson
@kthompson
i dont see arity but thanks for the info
Sorry, it's called nAry
arity seems like a more reasonable name lol
Kevin Thompson
@kthompson
Yea. That gives me something like
const toMap2 = R.reduce(
R.flip(
R.uncurryN(
2,
R.converge(R.call, [
x => R.flip(R.assoc)(x),
R.prop('id')
])
)
),
{}
);
i think the other implementation is a bit more clear/concise though
Twizzes
@Twizzes
@kthompson can you use Object.entries?
Kevin Thompson
@kthompson
i'm taking an array of objects and turning it into a map with the object's id as the key.
const toMap = R.pipe(
R.groupBy(R.prop('id')),
)
is the simplest way i can come up with

i think the other implementation is a bit more clear/concise though

:+1:

Kevin Thompson
@kthompson
Oh, I just found this...
const toMap3 = R.indexBy(R.prop('id'));
mitcho
gotta love that progression haha
Gezim Hoxha
Why does the object in filter (second param) have to have an index type of 'string'?
Lewis
@6ewis
hi
do you have a cleaner alternative
Lewis
@6ewis
const showColumns= (visibleColumns)  =>
const indexOfVisibleColumn = visibleColumns.map(col => col.name).indexOf(header.name);
if ( indexOfVisibleColumn !== -1) {
const { title } = visibleColumns[indexOfVisibleColumn]
title  ?
};

console.log("how does acc look like", acc);
return acc;
}, []);
;
Twizzes
@Twizzes
@6ewis
const visibleNames = R.map(R.prop('name'))

headers.filter(header => R.includes(R.prop('name')(header), visibleNames(visibleColumns)))
Julien
@customcommander
Is it right/appropriate to have this ramda-adjunct package “advertised" so many times in the Ramda Cookbook? I was tempted to raise a PR to remove this but wanted to check first. Personally I don’t think it is; it causes confusion more than anything.
Julien
@customcommander

I mean isn’t a link in “Related projects” enough?
https://github.com/ramda/ramda/wiki#related-projects

If other projects were doing the same thing, the Cookbook could become a messy place IMHO.

Oscar Bolmsten
@oscar-b
Any @types maintainer here? Either I'm daft or there's missing type for takeLastWhile when used with a string.
Daniel Cheung
@danvim
I just added "rambda": "^4.4.0" to my project. From the docs, I see that it supposedly has the invert and invertObj functions. However, I can't find them in the dist. When I open up src under the node_module, I do see invert and invertObj in their respective files though.
Anyone knows what has happened to them?
Syaiful Bahri
@syaiful6
@danvim i guess it's typo problem, it's ramda not rambda