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

Add reusable methods for implementing transformation operations in a strict way #325

Closed
julienrf opened this issue Dec 22, 2017 · 1 comment

Comments

@julienrf
Copy link
Contributor

Copy pasting the comment here:

I was also wondering if we should provide helpers to implement such operations in a strict way. For the view based version it is as easy as writing:

def map(f: Base => Base): RNA = fromSpecificIterable(View.Map(this, f))

We should probably have an equivalent strict version:

object Builder {

  def map[CC[_], A, B](source: IterableOnce[A], f: A => B, builder: Builder[B, CC[B]]): CC[B] = {
    for (a <- source) {
      b += f(base)
    }
    builder.result()
  }
}

So that users could just write:

def map(f: Base => Base): RNA = Builder.map(this, f, newSpecificBuilder())

And we could use it also in StrictOptimizedIterableOps.

The only part that I don’t like is that the builder is created in one place (user code) and used in a different place (framework code). This can be error prone because we really want the builder to be freshly created.

@julienrf
Copy link
Contributor Author

julienrf commented Jan 25, 2018

We should then use that to implement the missing StrictOptimizedMapOps and StrictOptimizedSetOps.

@julienrf julienrf self-assigned this Feb 15, 2018
@julienrf julienrf added this to the 0.11.0 milestone Feb 19, 2018
@julienrf julienrf removed this from the 0.11.0 milestone Mar 27, 2018
@szeiger szeiger added this to the Scala 2.13.0-M5 milestone Apr 24, 2018
julienrf added a commit to julienrf/scala that referenced this issue Jun 11, 2018
Add StrictOptimizedMapOps and StrictOptimizedSortedMapOps.

Only operations that were implemented more than once have been factored
out. Some other operations could be factored out so that they could
be reused by custom collection implementations.

Fixes scala/collection-strawman#325
julienrf added a commit to julienrf/scala that referenced this issue Jun 19, 2018
Add StrictOptimizedMapOps and StrictOptimizedSortedMapOps.

Only operations that were implemented more than once have been factored
out. Some other operations could be factored out so that they could
be reused by custom collection implementations.

Fixes scala/collection-strawman#325
julienrf added a commit to julienrf/scala that referenced this issue Jun 20, 2018
Add StrictOptimizedMapOps and StrictOptimizedSortedMapOps.

Only operations that were implemented more than once have been factored
out. Some other operations could be factored out so that they could
be reused by custom collection implementations.

Fixes scala/collection-strawman#325
julienrf added a commit to julienrf/scala that referenced this issue Jun 22, 2018
Add StrictOptimizedMapOps and StrictOptimizedSortedMapOps.

Only operations that were implemented more than once have been factored
out. Some other operations could be factored out so that they could
be reused by custom collection implementations.

Fixes scala/collection-strawman#325
julienrf added a commit to julienrf/scala that referenced this issue Jul 4, 2018
Add StrictOptimizedMapOps and StrictOptimizedSortedMapOps.

Only operations that were implemented more than once have been factored
out. Some other operations could be factored out so that they could
be reused by custom collection implementations.

Fixes scala/collection-strawman#325
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants