Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep symmetric behaviour when composing or using transducers with arrays and objects #2668

Open
xgbuils opened this issue Oct 10, 2018 · 2 comments

Comments

@xgbuils
Copy link
Contributor

xgbuils commented Oct 10, 2018

We have this code:

var mapSquare = R.map(x => x * x);
var mapInc = R.map(R.inc);
var intoArray = R.into([]);
var intoObject = R.into({});

var fn = R.compose(mapSquare, mapInc);
var xFn = R.compose(mapInc, mapSquare);

var arr = [1, 2, 3];
var obj = {a: 1, b: 2, c: 3};

fn(arr) // [4, 9, 16]
intoArray(xFn, arr) // [4, 9, 16]

// However ...
fn(obj) // {a: 4, b: 9, c: 16}
intoObject(xFn, obj) // throwing: reduce: list must be array or iterable
// but I also expect {a: 4, b: 9, c: 16}

I guess there are similar issues using filter. I could do a PR to fix it.

Best regards!

@CrossEye
Copy link
Member

I'd have to think carefully about what it means to support transducing on objects. I think about take(2) for instance, We think in Ramda as {a: 1, b: 2, c: 3} as equivalent to {b: 2, c: 3, a: 1}. The thought that take(2) would yield different results for them makes me pretty suspicious.

But if you have ideas, please go ahead and share them.

@CrossEye
Copy link
Member

Sorry, hadn't seen the PR when I responded. I'll check there.

@customcommander customcommander changed the title keeping simetric behaviour composing or using transducers in arrays and objects Keep symmetric behaviour when composing or using transducers with arrays and objects Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants