Skip to content

Make core collections stronger & consistent #30405

Closed
@matanlurey

Description

@matanlurey

Suggestions:

Iterable

  • bool contains(Object element) ➡️ bool contains(T element)

You never want to write this:

class Dog {}
class Cat {}

void main() {
  var dogs = [ new Dog(); ]
  var cat = new Cat();
  ...
  print(dogs.contains(cat)); // <-- Will never be true.
}

I ran into this today when I had a Set that used to be Set<A>, got changed to Set<B>, but code was never updated the check it for a B instead of an A, yet static analysis reported everything was fine.

List

  • List.from(Iterable elements) ➡️ List.from(Iterable<E> elements)

I'm not sure if this is blocked on #30355 or not.

  • List.unmodifiable(Iterable elements) ➡️ List.unmodifiable(Iterable<E> elements)

This is a common way to lose reified type information 😢

  • bool remove(Object element) ➡️ bool remove(T element)

Same issue as described above for Iterable#contains.

Map

  • Map.from(Map other) ➡️ Map.from(Map<K, V> other)
  • Map.fromIterable(Iterable iterable, { K key(element), V value(element) }) ➡️ Map.fromIterable(Iterable<E> iterable, { K key(E element), V value(E element) })
  • Map.unmodifiable(Map other) ➡️ Map.unmodifiable(Map<K, V> other)
  • bool containsKey(Object key) ➡️ bool containsKey(K key)
  • bool containsKey(Object value) ➡️ bool containsValue(V value)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.core-2library-core

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions