Closed
Description
This issue was originally filed by @MarkBennett
What steps will reproduce the problem?
- Generate a List of key/value pairs (such as by parsing a query string)
- Attempt to create a new Map from the list.
- 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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
madsager commentedon Apr 19, 2012
Added Area-Library, Triaged labels.
DartBot commentedon Apr 19, 2012
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 commentedon Apr 20, 2012
This comment was originally written by ladicek@gmail.com
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 commentedon Aug 22, 2013
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.
Bump pub