Added alternative compile.to syntax, providing more efficient and uniform collection building #1659
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1654
This PR introduces an overload of
.compile.to
that takes aCollector[O]
. Best explained via usages:I deprecated
.compile.{toMap, toChunk}
as they aren't often used and their functionality is provided by the above. I left.compile.string
b/cString
doesn't have a companion object, makings.compile.to(String)
impossible. I lefttoList
andtoVector
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 withChunk
in this PR), you can define an implicit conversion from the companion to aCollector
(like done in this PR forArray
) or you can define an explicit instance ofCollector
and require usage like.to(yourInstance)
.