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

Collection.Indexed implementations inconsistently handle non-integer indices #1890

Open
nex3 opened this issue Nov 12, 2021 · 2 comments
Open

Comments

@nex3
Copy link

nex3 commented Nov 12, 2021

The List class always seems to round non-integer indices down, while OrderedMap.entrySeq() seems to return undefined if the index isn't an exact representation of an integer. I haven't investigated other implementations to see if they differ. I'm not sure which behavior is better, but either way I'd expect them to be consistent.

const immutable = require("immutable");

console.log(immutable.List([[1, 2], [3, 4]]).get(0.1)); // [1, 2]
console.log(immutable.OrderedMap([[1, 2], [3, 4]]).entrySeq().get(0.1)); // undefined
@jdeniau
Copy link
Member

jdeniau commented Nov 12, 2021

I do not have the implementation in mind right now, but it's probably because a Map is key/value, so the key is strict, while a List accessor is numbered indexed, so 0.1 is converted to 0.

If something should be made, then probably the List should either return undefined or throw an error (but immutable does not really throw errors).

For the record : do you use Typescript? And if so, does it report an error?

@jdeniau
Copy link
Member

jdeniau commented Nov 12, 2021

I answer to my own question : as Typescript does not handle integer, 0.1 is a valid value for List.get

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