the @@transducer/init,result/step
forms an object referred to as a transformer. The transformer represents a single transformation (map, all, any, drop, take, filter,...) and facilitates chaining many transformers together without creating intermediate collections between each transformer.
reduced
, AFAIK, is a kill switch for reduce
. when you call reduced(result)
in your reducer function, the iterator in reduce
sees your result is wrapped in a special object, takes out the result
and stops iterating.
I'm not clear about what you referred to as ransducer/value.
transduce
for quite awhile until I saw the example didn't bother writing those functions adhering to a certain interface.
R.transduce
, it uses its arguments to construct the initial transformer, which is then passed to your iterator function chain compose(map(add(1)), take(2))
where map
and take
see their data object is a transformer, and each adds another link in the transformer chain and passes it on. Once done, I think R.transduce
can start iterating with the final chain of transformers.
@@transducer/init,step,result
properties. From there, I have no idea how it works :D
reduced
function you were talking about.
reduced
take(2)
.
['a', 'b', 'c', 'd', 'e']
, is there an elegant way to select every second element? ['a', 'c', 'e']
or ['b', 'd']
, in this case.
const value = ['a', 'b', 'c', 'd', 'e'];
R.pipe(
R.splitEvery(2),
R.filter(R.pipe(R.length, R.equals(2))),
R.map(R.last)
)(value);
//=> ['b', 'd']
R.over(everyOther, R.map(R.toUpper), ['a', 'b', 'c', 'd', 'e'])
.
const value = ['a', 'b', 'c', 'd', 'e'];
R.addIndex(R.filter)((a, i) => 0 === i %2, value);
//=> ['a', 'c', 'e']
ooo, lenses.
const evensLens =
R.lens(list => {
const result = [];
for (let idx = 0; idx < list.length; idx += 1) {
if (idx % 2 === 0) {
result.push(list[idx]);
}
}
return result;
},
(evens, list) => {
const result = [];
for (let idx = 0; idx < list.length; idx += 1) {
if (idx % 2 === 0) {
result.push(evens[idx / 2]);
} else {
result.push(list[idx]);
}
}
return result;
});
R.over(evensLens, R.map(R.toUpper), ['a', 'b', 'c', 'd', 'e']);
// => ['A', 'b', 'C', 'd', 'E']
arguments[0] is undefined
. http://goo.gl/HN7Ggg
const a = over((lensIndex(0)), R.toUpper);
const b = over((lensIndex(2)), R.toUpper);
const c = over((lensIndex(4)), R.toUpper);
const calc = R.compose(a, b, c);
expect(calc(value)).to.deep.equal(['A', 'b', 'C', 'd', 'E']);
const value = ['a', 'b', 'c', 'd', 'e'];
const filterIndex = R.addIndex(R.filter);
const isOdd = (a, i) => 1 === i % 2;
const isEven = R.pipe(isOdd, R.not);
const getter = filterIndex(isOdd);
const setter = (odds, list) => {
const interleave = (a) => {
if (isEven(0, a.li)) {
if (a.li >= list.length) { return false; }
else { return [list[a.li], { li: a.li + 1, oi: a.oi }]; }
}
else {
if (a.oi >= odds.length) { return false; }
else { return [odds[a.oi], { li: a.li + 1, oi: a.oi + 1 }]; }
}
};
return R.unfold(interleave, { li: 0, oi: 0 });
};
const lens = R.lens(getter, setter);
R.over(lens, R.map(R.toUpper), value);
//=> ['a', 'B', 'c', 'D', 'e']
toUpper
instead of R.toUpper
.
argument[0] is undefined
error. had defined isEven
in terms of itself rather than isOdd
. http://goo.gl/7u98ux
R.unfold
.
unnest
appears to take transformers, but doesn't work properly in that context.
isOdd
and isEven
? It seems it would be simpler without them.
const i = idxs[idx];
is amusing.
list[idxs[idx]]
was messing with my OCD :pFuture
seems to handle recurring events: https://davidchase.github.io/ramtuary/#?code=var%20f%20%3D%20new%20Future%28function%28rej%2Cres%29{%20%0A%20%20setInterval%28%28%29%3D%3E%20res%2842%29%20%2C%202000%29%20%0A}%29%0Af.map%28x%3D%3Ex%2B1%29.map%28x%3D%3Ex*2%29.fork%28console.error%2C%20console.log%29
Hi there! How can I pass JSON.stringify
as parameter in R.ifElse
?
R.ifElse(R.is(Object), JSON.stringify.bind(JSON), R.identity)({})
This returns function of two arguments, instead of expected "{}"
R.unary(JSON.stringify)
JSON.stringify
need to be bound in some browsers/environments?
R
transduce
filed under list? I thought the point of transducers
was you are able to iterate over any sort of object by specifying a stepper function?
list
is - it could be that Ramda views a list as something that you can iterate over?
fantasy-land
spec?
R.clone
claims to make a deep copy
@jethrolarson I spent time with cycle.js a few months back. it's pretty nice from a minimal point of view and the integration with Rx observable was nice to a point. I found it relatively easy to work with when my UI had a fixed number of elements on the page. Anything involving dynamic UI elements that didn't benefit from event delegation (like one or more control panels on a dashboard), and I couldn't wrap my head around how to create the UI elements on the fly and wire them into the Rx observables.
Not to say that it couldn't be done. I went back to React because I needed to make progress. At the time, cycle.js was starting to transition to nested dialogues which weren't well documented. I hope to give cycle.js another try when I find time to tinker again.