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

Added alternative compile.to syntax, providing more efficient and uniform collection building #1659

Merged
merged 5 commits into from Oct 15, 2019

Conversation

mpilquist
Copy link
Member

@mpilquist mpilquist commented Oct 12, 2019

Fixes #1654

This PR introduces an overload of .compile.to that takes a Collector[O]. Best explained via usages:

s.compile.to(List)
s.compile.to(Array)
s.compile.to(Map)
s.compile.to(Chunk)
s.compile.to(ByteVector)

I deprecated .compile.{toMap, toChunk} as they aren't often used and their functionality is provided by the above. I left .compile.string b/c String doesn't have a companion object, making s.compile.to(String) impossible. I left toList and toVector undeprecated as they are used a lot and forcing folks to change syntax seemed hostile. Finally, I left .to[C] undeprecated because Scala's deprecation checker has a bug which flags uses of .to(collector) as deprecated calls despite only type param version being deprecated.

To build a custom collector, you can either implement CollectorK on the companion (like is done with Chunk in this PR), you can define an implicit conversion from the companion to a Collector (like done in this PR for Array) or you can define an explicit instance of Collector and require usage like .to(yourInstance).

@SystemFw SystemFw merged commit f8417d1 into typelevel:master Oct 15, 2019
@mpilquist mpilquist added this to the 2.1.0 milestone Nov 5, 2019
@mpilquist mpilquist deleted the topic/better-to branch February 18, 2020 12:56
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.

Alternative, efficient, extensible replacement for to
2 participants