Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature Request: Immutable [List|Set|Map] #3700

Closed
kevmoo opened this issue Jun 17, 2012 · 2 comments
Closed

Feature Request: Immutable [List|Set|Map] #3700

kevmoo opened this issue Jun 17, 2012 · 2 comments
Labels
closed-duplicate Closed in favor of an existing report

Comments

@kevmoo
Copy link
Member

kevmoo commented Jun 17, 2012

I use collections (list, map, set) a lot. One of the pains of .NET is the legacy around collection interfaces: no support for immutable.

The best one gets is IList.IsReadOnly, which is too little to late.

My humble request:

  ImmutableList<E>
  ImmutableMap<K, V>
  ImmutableSet<E>

The common pattern, in .NET (and it seems in Dart) is to expose the existing types and then throw exceptions in mutate operations (add, remove, clear, etc)--at least from looking at ImmutableList<E>.

This creates clutter in documentation and exceptions at runtime that could easily be resolved by the type system.

I want to expose lists, maps, and sets via properties without having to wrap everything in a wrapper and confuse my user.

Is myObject.items.clear() supported or not?

I want to accept lists, maps, and sets via method/constructor/factory paramaters with the explict promise that I intend to inspect, but not mutate the input.

Scala has an amazing approach here by having a whole namespace of immutable collection interfaces (and classes).
http://www.scala-lang.org/docu/files/collections-api/collections_1.html

While I’d love to have in-the-box immutable collections in Dart, I’d settle for common interfaces that serve as superclasses for the mutable versions.

While I fully support pushing off non-essential features for later, I must plead a bit here.

If v1 ships without immutable collection support, it will be prohibitive to introduce this concept later.

Help us ship better code.

@sethladd
Copy link
Contributor

Added Duplicate label.
Marked as being merged into #236.

@kevmoo kevmoo added Type-Defect closed-duplicate Closed in favor of an existing report labels Jun 17, 2012
@trinarytree
Copy link

why was this issue merged into #236?
that issue is entitled "Immutable List/Map". notice how the word "Set" isn't in there.
in order to mark this issue as a dup of that one, you either have to expand the scope of
that issue to include Sets (at which point it would have to be re-opened)
or you would have to un-dup this one.

at any rate, dart still doesn't have an immutable/unmodifiable Set with an interface similar to that for List and Map. e.g. dart does have UnmodifiableListView and UnmodifiableMapView, but no UnmodifiableSetView. yes, i know that there is built_collection, but i said "...with an interface similar to..." and such functionality should be equally core as UnmodifiableListView.

another example of the irregular treatment of Set:
List and Map both have an unmodifiable constructor, but Set doesn't.

for reference, #11256 also requests an unmodifiable Set and it was closed as fixed, but i can't figure out why since the request in the title doesn't seem to be resolved.

This issue was closed.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

3 participants