isi-vista / immutablecollections

A library for immutable collections, in the spirit of Guava's Immutable Collections.
MIT License
3 stars 2 forks source link

Consider providing same-return-type slice methods #21

Open gabbard opened 5 years ago

gabbard commented 5 years ago

On #20, @ConstantineLignos noted

One comment to remove, and then one general question: in slicing, typically slicing an X[T] returns another X[T]. For example, a list slice returns a list, a tuple slice returns a tuple. Here, when an ImmutableList/Set is sliced, we return a tuple. I don't know whether this is the right thing to do. The current solution is probably the best performance-wise, but it is a bit unusual.

@rgabbard replied

re: slicing, I think the performance impact is probably too big to do anything else, and the type signature should hopefully alert the user to any clash of expectations (and if they aren't using mypy, it's their own fault :-P ). We could consider adding another method to produce ImmutableX-typed slices, though, for those willing to pay the performance penalty.