This repository was archived by the owner on Dec 22, 2021. It is now read-only.
This repository was 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
Description
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.