Skip to content

Map/filter looses the underlying collection type #23

Closed
@Tvaroh

Description

@Tvaroh

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();
  • ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions