Add Parallel.apply overload with one type parameter #3031
Merged
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.
I left this out of #3012 intentionally, since I generally avoid overloading and hate the
scala.DummyImplicit
hack, which is necessary here, and since I didn't think the need for it would come up that often.As I've been working more with 2.0.0-RC2 this week, though, I've decided that we really do want this
Parallel.apply
in 2.0, for a few reasons:apply
is pretty useless.apply
is go toimplicitly
, which in this case is pretty unhelpful for something likeParallel[Stream]
, since its static return type is unrefined. To get a usefully typed instance, you have to go to something like Shapeless'sthe
or define your own version ofParallel.apply
with a single parameter.Parallel
syntax still can be not a great user experience, for a number of reasons, like the fact that if you're working with something likeEitherT
, you might expect theParallel[EitherT[F, E, *]]
to be in implicit scope, since a lot ofEitherT
's other instances are (Traverse
,Monad
, etc.), but no, it has to be imported. When I get frustrated by a type class's syntax, I just fall back to trying to use itsapply
and call the methods on the instance directly, which at least shrinks the problem space. In this case, where frustration is especially likely, you really want aParallel.apply
that isn't useless.The implementation is pretty straightforward apart from the horrible
scala.DummyImplicit
part, but without that we'd need a new method name, and the whole point here is easy discovery and matching users' expectations, so I think overloading is the right approach.The tests are pretty simple checks that the static types come out right. I've also added tests for the old two-type-parameter overloads for consistency.
Update: note that this change technically breaks source compatibility—it causes the following code not to compile, although it was fine in 2.0.0-RC2:
Same with this (it compiles with 2.0.0-RC2, but not after this change):
Neither of the following compile with 2.0.0-RC1, but off the top of my head I'm not sure why (I only tried 2.13):Both of the following are also fine with 1.x or 2.0.0-RC1 on 2.12 (not 2.0.0-RC1 on 2.13, but that's because of some unrelated aliasing stuff):There's no reason I can think of that someone would want to do any of this in real code, and I'd be very surprised if it causes problems for anyone.