rtfeldman / seamless-immutable

Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.
BSD 3-Clause "New" or "Revised" License
5.37k stars 195 forks source link

Should without() accept numeric keys? #129

Closed kalafut closed 8 years ago

kalafut commented 8 years ago

I recently ran into an issue where numeric IDs were being used to build and work with an object. This didn't work with the without() function. Not a big deal, but it is inconvenient to worry about "toString()" before using a variable, and other seamless functions seems to handle numeric keys:

let o = Immutable({ "foo":"bar", 42:"dog" })
console.log(o.set(42, "cat")) // yep  {42: "cat", foo: "bar" }
console.log(o.without(42))    // nope {42: "dog", foo: "bar" }
console.log(o.without("42"))  // yep  {foo: "bar" }

The scenario for me was using an ID from a received JSON object. The sender may store the value as 42 or "42", and ensuring it is a string for this one function is a little inconsistent.

Thanks, Jim

rtfeldman commented 8 years ago

Seems reasonable as long as it's only for numbers. Calling String.valueOf on e.g. null would seem more likely to mask errors than avoid them.

I'd gladly accept a PR for this! 😄

kalafut commented 8 years ago

OK, I'll work on it.