Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

A simpler way to force a view to get back the initial collection type #289

Closed
julienrf opened this issue Nov 6, 2017 · 5 comments
Closed
Milestone

Comments

@julienrf
Copy link
Contributor

julienrf commented Nov 6, 2017

Currently, if a user takes as parameter a List[Int] and get a View from it, there is no automatic way to get back a List, unless the user explicitly mentions the companion object: xsView.to(List). I wish we could just write xs.force(), so that if we change the type of the underlying collection to be a Vector we don’t have to repeat the change when calling .to(Vector).

#144 Provides a solution to this problem by introducing the concept of view transformers. However it only works with unsorted collection types and with collection type constructors of kind * -> *. We should investigate the ability to also support sorted collections and other kinds.

@szeiger
Copy link
Contributor

szeiger commented Apr 23, 2018

IMHO this is unnecessary. Do you ever care about getting the same type as the source collection back without knowing what it was? Either you know what you start with or you know what you want to build no matter what.

(If we should end up doing this #543 needs to be reopened and fixed properly)

@szeiger szeiger added this to the backlog milestone Apr 23, 2018
@Ichoran
Copy link
Contributor

Ichoran commented Apr 23, 2018

@szeiger - Very often the choice of collection is made for performance reasons. Having it be maintained without knowing what it was is usually the performance-friendly option; eager operations on Seq have this property. Losing this property for views is okay, but it is a loss. (We already deal with this loss with Iterator, for instance.)

@SethTisue
Copy link
Member

SethTisue commented Apr 24, 2018

Losing this property for views is okay, but it is a loss

I take your point, but there is a sense in which it also a gain, because it is simpler. No longer carrying this information makes it easier, overall, to understand what views are and how they behave.

@Ichoran
Copy link
Contributor

Ichoran commented Apr 24, 2018

@SethTisue - I agree. My point was only that it's a tradeoff. I don't have a strong opinion about which consideration is more important. Since it is work to make it remember the information, I would lean more towards "forget the underlying type".

@SethTisue
Copy link
Member

looks like this isn't happening.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants