Skip to content

Supporting constructing Maps from Lists of key/value pairs #2642

Closed
@DartBot

Description

@DartBot

This issue was originally filed by @MarkBennett


What steps will reproduce the problem?

  1. Generate a List of key/value pairs (such as by parsing a query string)
  2. Attempt to create a new Map from the list.
  3. Fail.

What is the expected output? What do you see instead?

    I would expect the Map to include a constructor that could construct a Map from a List of key/value pairs similair to the Hash constructor in Ruby (http://rdoc.info/stdlib/core/1.9.3/Hash.%5B%5D)

What version of the product are you using? On what operating system?

Version 0.1.0.201204121423, Build 6479
Dart SDK version 6478, Dartium version

Please provide any additional information below.

Activity

madsager

madsager commented on Apr 19, 2012

@madsager
Contributor

Added Area-Library, Triaged labels.

DartBot

DartBot commented on Apr 19, 2012

@DartBot
Author

This comment was originally written by @seaneagan


This would involve introducing some sort of Pair<K, V> interface, so this could then be done by having Map<K, V> extend Collection<Pair<K, V>> (see issue #326 discussion), and then changing the parameter type of the Map.from constructor:

Map.from(Collection<Pair<K, V>>);

DartBot

DartBot commented on Apr 20, 2012

@DartBot
Author

This comment was originally written by ladicek@gmail.com


This would involve introducing some sort of Pair<K, V>

Not necessarily. I think that the original poster wants (and the link to RDoc confirms) a constructor that takes a list, which contains keys and values interleaved, like this:

Map<int, String> m = new Map.fromInterleaved(1, "a", 2, "b");

"fromInterleaved" isn't exactly the best name, but I think that it also isn't the best idea -- especially when full Map literals come (the current limitation to String keys is kinda annoying, really).

lrhn

lrhn commented on Aug 22, 2013

@lrhn
Member

We don't particularly want to introduce pairs of keys/values.
We have Map.fromIterable which would work:
  new Map.fromIterable(pairList, (p) => p.first, (p) => p.second)
or if you don't keep the key and value in the same list:
  new Map.fromIterables(keys, values)


Added NotPlanned label.

added
area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
closed-not-plannedClosed as we don't intend to take action on the reported issue
on Aug 22, 2013
added a commit that references this issue on Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.closed-not-plannedClosed as we don't intend to take action on the reported issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @madsager@lrhn@DartBot

        Issue actions

          Supporting constructing Maps from Lists of key/value pairs · Issue #2642 · dart-lang/sdk