Closed brakmic closed 9 years ago
My thoughts:
object-list
is strictly non-destructive. It should not mutate the passed in list. Instead, it should return a new list. I didn't look at the linked source well enough to make sure none of its methods mutate..RemoveByIndex()
– functionality available on list prototype as .filter()
, but we add something that would be an exact opposite of .slice()
(return the filtered list instead of the sliced out subset)..Remove()
– Removes an item from the collection (see above, but we should only have one method for this, not two -- the range version should default to a single item if the second range parameter is not supplied)..SerializeToJSON()
– Built into JS as JSON.stringify()
, but we could add a convenience method called .json()
that is a safe version that does not throw..OrderBy()
, .OrderByDescending()
– Orders the list bases on the property passed in. Good idea. =).ElementAt()
– Returns an object from the collection at a set index..Contains()
– Currently experimental for Array.prototype
(ES7). We could surface this as .includes()
pretty easily. .add()
- already exists as Array.prototype.push()
(I'm assuming that all lists passed in supply Array.prototype
compatible interface. .push()
does not do type enforcement (and shouldn't, it would make the library less generally useful for things like APIs). Maybe we should explicitly document the expected API, and inherit passed-in list prototype on the returned object? =).count()
- already exists as Array.prototype.length
, but could be wrapped as a method and should be used with caution for compatibility with infinite streams and generators..where()
- already exists as .where()
in this lib. Not documented because we need a bug fix for multiple clauses.Good ideas stolen, the rest scrapped. See future.
I found this blog post about a library that offers LINQ-like querying of objects / lists /dictionaries.
http://codeiain.azurewebsites.net/javascript-generic-list-with-c-linq-style-functionality/
Regards, Harris