Map/filter looses the underlying collection type
See original GitHub issueExample:
var v = Immutable.Vector(1, 2, 3)
v.toString() // "Vector [ 1, 2, 3 ]"
var v2 = v.map(function (x) { return x + 1; })
v2.toString() // "Seq [ 2, 3, 4 ]"
v2.delete(0) // TypeError: undefined is not a function
So, one must issue toVector()
after the transformation to get original structure type back. This is very inconvenient for a library user.
I understand this is due to laziness so possible options may be:
- provide strict versions of
map/filter/etc
; - somehow preserve set of methods and observable behavior of the original data structure;
- provide single method replacing
toVector/toMap/etc
and allowing to get original data structure after transformation back, e.g.force()
; - …
Issue Analytics
- State:
- Created 9 years ago
- Reactions:1
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Swift using CollectionType .filter .indexOf and .map to find ...
filter returns a potential collection of objects - still a collection. Therefore you cannot assign the result to something of type (code:Int64, ...
Read more >Reading 25: Map, Filter, Reduce
The abstract sequence type we defined above exists in Java as Stream , which defines map , filter , reduce , and many...
Read more >Collections
Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type.
Read more >Iterator in std
The most basic pattern in which collect() is used is to turn one collection into another. You take a collection, call iter on...
Read more >Generic Map, Filter and Reduce in Go | by Erik Engheim
The iterator stores the mapping function mapper and iterator source to the underlying collection. The Map function itself is pretty dumb, it ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well, in Python3 you also get generator instead of List when running filter and need to convert it explicitly. I think, explicit is better than implicit.
https://docs.python.org/3.4/library/functions.html#filter
I see.