frptools / collectable

High-performance immutable data structures for modern JavaScript and TypeScript applications. Functional interfaces, deep/composite operations API, mixed mutability API, TypeScript definitions, ES2015 module exports.
MIT License
273 stars 14 forks source link

MAIN(fix): Error when using setIn() to set a deeply nested value, fixes #55 #59

Closed ariesshrimp closed 7 years ago

ariesshrimp commented 7 years ago
ariesshrimp commented 7 years ago

I feel like setDeep would make more sense if its checks were reversed.

For example, if it worked like so:

if (not a valid collection) return fromArray()
return IndexedCollection.logic()

but I couldn't see a nice way of writing that. In other words, I think this is a case where the conditions should represent positive guards against the non-collection path, rather than confirming the happy path.

ariesshrimp commented 7 years ago

Also, I took this non-primitive-check trick from here: https://stackoverflow.com/questions/31538010/test-if-a-variable-is-a-primitive-rather-than-an-object

Is there a better way to do this using Typescript powers?

axefrog commented 7 years ago

In @frptools/core, there are the types concrete and defined, which are examples of how you'd do it in TypeScript.

You could write a function like this:

type Primitive = null|undefined|string|number|boolean|symbol;
function isConcrete(value: any): value is Primitive {
  return value == Object(value); // tslint:disable-line
}
axefrog commented 7 years ago

Thanks for the pull request, the code looks good to me!

axefrog commented 7 years ago

New packages published.