Skip to content

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

Closed
@kevmoo

Description

@kevmoo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed-duplicateClosed in favor of an existing report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions