isc30 / linq-collections

Strongly typed Linq and Collections implementation for Javascript and TypeScript (ECMAScript 5)
https://www.npmjs.com/package/linq-collections
MIT License
119 stars 12 forks source link

Readonly collections? #12

Closed apawsey closed 6 years ago

apawsey commented 6 years ago

Hey...

I'm still getting busy trying to add contributions, don't think I've forgotten :smile:

In the meantime, I just wondered if you've thought about adding 'readonly' collections? I know it's never going to be exactly perfect in the typescript/javascript world, but it's a nice addition to imply usage to users of exposed properties.

Thanks.

isc30 commented 6 years ago

Hi 😄

There is already an IQueryable<T> interface that abstracts all readonly methods from all collection types. It can be used as return or member type to explicitly force that the content is constant (readonly). Is that what you need? if not, please give me an example of your proposal

Thanks a lot ;D

isc30 commented 6 years ago

I splitted IList and IDictionary into different interfaces:

IReadOnlyList<T>, IList<T> (extends readonly list)

IReadOnlyDictionary<K,T>, IDictionary<K,T> (extends readonly dictionary)

Both IList and IDictionary have asReadOnly() method (simple internal cast)