-
Notifications
You must be signed in to change notification settings - Fork 607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Collector.supportsFactory #2827
Fix Collector.supportsFactory #2827
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally thought that with this change we could also "remove" the other Factory
related implicit, but it seems no. It turns out that things like List
are not a Factory[A, List[A]]
but rather they provide an implicit conversion to such type but the compiler doesn't apply two implicit conversions at the same time.
implicit def supportsFactory[A, C[_], B]( | ||
f: Factory[A, C[B]] | ||
): Collector.Aux[A, C[B]] = make(Builder.fromFactory(f)) | ||
implicit def supportsCollectionFactory[A, C](f: Factory[A, C]): Collector.Aux[A, C] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If anyone has a better name I am all ears.
@@ -50,6 +52,9 @@ private[fs2] trait CollectorPlatform { self: Collector.type => | |||
} | |||
|
|||
private[fs2] trait BuilderPlatform { self: Collector.Builder.type => | |||
def fromCollectionFactory[A, C](f: Factory[A, C]): Builder[A, C] = | |||
fromBuilder(f.newBuilder) | |||
|
|||
def fromFactory[A, C[_], B](f: Factory[A, C[B]]): Builder[A, C[B]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we deprecate this one?
builder: collection.mutable.Builder[A, C[B]] | ||
): Builder[A, C[B]] = | ||
new Builder[A, C[B]] { | ||
protected def fromBuilder[A, C]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this change makes sense and doesn't break binary compatibility.
Although, the code compiled without it so we revert it if you prefer.
3849ce9
to
4c6c0ea
Compare
AFAIK this is the best practice and allows types like
BitSet
to be properly used.