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

Pull up the newBuilder method from Buildable to IterableOps. #110

Merged
merged 2 commits into from
Jun 21, 2017

Conversation

julienrf
Copy link
Contributor

And also:

  • Rename newBuilder to newSpecificBuilder.
  • Rename Buildable to StrictOptimizedIterableOps.
  • Add XxxWithBuilder variants to all kinds of factories.

But the main change is that now all Iterabe have this protected method that makes it possible to create a strict builder for them. This change is supposed to make it simpler to provide default implementations for several methods (such as groupBy, see #108). It might also simplify #97.

Rename newBuilder to newSpecificBuilder.
Rename Buildable to StrictOptimizedIterableOps.
Add XxxWithBuilder variants to all kinds of factories.
@julienrf julienrf requested review from odersky, szeiger and Ichoran June 14, 2017 10:11
protected[this] def fromSpecificIterable(coll: Iterable[A]): View[A] = fromIterable(coll)

protected[this] def newSpecificBuilder(): Builder[A, View[A]] =
immutable.IndexedSeq.newBuilder().mapResult(_.view)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how newSpecificBuilder() is implemented in View.

Note that (fortunately) the View factory object does not publicly expose this builder.

@@ -36,6 +36,9 @@ class LazyList[+A](expr: => LazyList.Evaluated[A])

protected[this] def fromSpecificIterable(coll: collection.Iterable[A]): LazyList[A] = fromIterable(coll)

protected[this] def newSpecificBuilder(): Builder[A, LazyList[A]] =
IndexedSeq.newBuilder().mapResult(_.to(LazyList))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is the builder for LazyList. Again, it is not publicly exposed.

@julienrf
Copy link
Contributor Author

I also just added a commit that removes builders from mutable collections. I don’t think they are useful: the main purpose of builders is to make it possible to build immutable collections in an imperative way. We don’t need that for mutable collections.

@@ -47,6 +43,18 @@ object IterableFactory {

}

trait IterableFactoryWithBuilder[+CC[_]] extends IterableFactory[CC] {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you think of StrictIterableFactory instead of IterableFactoryWithBuilder?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think many of these names are way too long without being fully documenting (which would be the main reason to have long names). We should aim for at most two words describing the type of collection (preferably one), and one word describing the concept except maybe two when it's an unusual case like Ordering. I don't think we should worry about it now, though; let's get the functionality working first, and then worry about compact suggestive names.

@Ichoran
Copy link
Contributor

Ichoran commented Jun 15, 2017

I have to say I'm not very fond of all of the formulaic boxing and indirection in the factory companions. Isn't there some way using package private to avoid indirection by allowing "delegation" to just be returning the same object with a different type?

Regarding allowing strict builders, I like in principle the idea of having them available when needed (though not the easiest thing to use), but I'm having trouble fully grasping the consequences especially for correctness: can you get violations of expected behavior if you don't manually keep both up to date?

@julienrf
Copy link
Contributor Author

can you get violations of expected behavior if you don't manually keep both up to date?

keep both what?

@Ichoran
Copy link
Contributor

Ichoran commented Jun 16, 2017

I guess what I mean is: are there both strict and lazy builders for the same collections, or does one just defer to the other? (Even if yes, I guess that's fine; it just should be documented clearly so if you change how something is built, you know to fix both places.)

@julienrf
Copy link
Contributor Author

julienrf commented Jun 16, 2017

We will have both strict and lazy builders for the same collections so yes, we should probably document that better.

@julienrf
Copy link
Contributor Author

Any objection to merge this one? I think we can still further discuss whether we want distinct XxxFactory and XxxFactoryWithBuilder or merge them.

@julienrf julienrf mentioned this pull request Jun 20, 2017
@julienrf julienrf merged commit c52e348 into master Jun 21, 2017
julienrf added a commit that referenced this pull request Jun 22, 2017
@julienrf julienrf deleted the iterable-builders branch June 28, 2017 09:15
@szeiger szeiger mentioned this pull request Jun 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants