question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Map/filter looses the underlying collection type

See original GitHub issue

Example:

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:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hleumascommented, Aug 14, 2014

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

0reactions
hleumascommented, Jun 29, 2015

I see.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found