callback
helper function I have written below. Could someone please let me know if it exists?const callback = (fn) => (...args) => () => fn(...args)
const obj = {
method: (x, y) => x + y
}
const exists = always(has('method', obj))
const execute = callback(prop('method', obj))('Invoke ', 'Fn')
when(exists, execute)(null)
I would push for ADTs over currying for sure. Point free without static types can make things harder to read until used to it. It's really nice if your team is into it, but otherwise I think it's best used sparingly. There are certain places where currying makes a ton of sense (DI is often one of those cases).
I can't tell you how often I see a good use for Maybe or Either. They come up everywhere, and are especially helpful in dynamically typed code.
(arg1, arg2) => async () => { ... }
ap
is a great use case for curry
except that it relies on the understanding of uh... container types
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
select
and reject
. I really liked it at the time
map
is also nice - lodash has mapValues
which I like less
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}]
const assignById = converge(call, [
flip(assoc),
prop('id')
]);
assignById({id: 'abc', taco: 'time'}, {}) // => {abc: {id: 'abc', taco: 'time'} }