Skip to content
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

Merged
merged 1 commit into from
Feb 22, 2022

Conversation

BalmungSan
Copy link
Contributor

AFAIK this is the best practice and allows types like BitSet to be properly used.

Copy link
Contributor Author

@BalmungSan BalmungSan left a 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] =
Copy link
Contributor Author

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]] =
Copy link
Contributor Author

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](
Copy link
Contributor Author

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.

@BalmungSan BalmungSan force-pushed the fix-collector-iterable-factory branch from 3849ce9 to 4c6c0ea Compare February 20, 2022 20:32
@mpilquist mpilquist merged commit f0ebba0 into typelevel:main Feb 22, 2022
@BalmungSan BalmungSan deleted the fix-collector-iterable-factory branch February 22, 2022 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants