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

Make Parallel's F a type member #3012

Merged
merged 2 commits into from Aug 26, 2019
Merged

Conversation

@travisbrown
Copy link
Contributor

@travisbrown travisbrown commented Aug 26, 2019

Fixes #2233. We'd been holding off on this change because we thought it would necessarily require both source and binary compatibility breakage, but it turns out we can fix it without breaking binary compatibility with Cats 1.x.

Note that this change does break source compatibility pretty dramatically, but the migration path will generally be pretty clear (add .Aux, maybe an explicit type parameter here or there). Anyway, as Rob Norris says here, the current API is so awkward to use that this is unlikely to break much code.

With this change you can use parallel syntax without having to thread an extra type parameter everywhere through your code. Taking an example from the README of cats-par (a library for working around the limitations of the current API), this PR allows us to write the following:

import cats._
import cats.implicits._
import cats.data._

def withNewParallel[F[_]: Monad: Parallel, A, C, D](
  as: List[A],
  f: A => Kleisli[F, C, D]
): Kleisli[F, C, List[D]] =
  as.parTraverse(f)

With the current API we have to include an extra parameter G[_], both here and all the way up our call stack:

def withOldParallel[F[_]: Monad, G[_], A, C, D](
  as: List[A],
  f: A => Kleisli[F, C, D]
)(implicit P: Parallel[F, G]): Kleisli[F, C, List[D]] =
  as.parTraverse(f)

Note that the only changes to the tests are a few Auxs (and one fewer type parameter in one applicativeError call); otherwise the usage exercised in the tests didn't require changes.

Copy link
Member

@LukaJCB LukaJCB left a comment

Looks good to me, thanks! This has been a long time coming

Loading

@codecov-io
Copy link

@codecov-io codecov-io commented Aug 26, 2019

Codecov Report

Merging #3012 into master will decrease coverage by <.01%.
The diff coverage is 98.11%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #3012      +/-   ##
=========================================
- Coverage    93.6%   93.6%   -0.01%     
=========================================
  Files         368     368              
  Lines        6948    6946       -2     
  Branches      188     185       -3     
=========================================
- Hits         6504    6502       -2     
  Misses        444     444
Impacted Files Coverage Δ
...ain/scala/cats/laws/discipline/ParallelTests.scala 100% <ø> (ø) ⬆️
...a/cats/laws/discipline/NonEmptyParallelTests.scala 100% <ø> (ø) ⬆️
core/src/main/scala/cats/syntax/parallel.scala 62.5% <0%> (ø) ⬆️
core/src/main/scala/cats/data/NonEmptyList.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/Parallel.scala 84.37% <100%> (ø) ⬆️
core/src/main/scala/cats/package.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/data/WriterT.scala 91.26% <100%> (-0.07%) ⬇️
...rc/main/scala/cats/laws/NonEmptyParallelLaws.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/data/Ior.scala 98.52% <100%> (ø) ⬆️
core/src/main/scala/cats/data/Kleisli.scala 90.9% <100%> (-0.09%) ⬇️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14e525a...5d7ab29. Read the comment docs.

Loading

@kailuowang kailuowang added this to the 2.0.0-RC1 milestone Aug 26, 2019
@kailuowang kailuowang removed this from the 2.0.0-RC1 milestone Aug 26, 2019
@kailuowang kailuowang added this to the 2.0-RC2 milestone Aug 26, 2019
@LukaJCB LukaJCB requested a review from kailuowang Aug 26, 2019
@mpilquist mpilquist self-requested a review Aug 26, 2019
@kailuowang
Copy link
Member

@kailuowang kailuowang commented Aug 26, 2019

NIce, how come this (it doesn't break BC) didn't occur to us.

Loading

@kailuowang kailuowang merged commit 81bbbb2 into typelevel:master Aug 26, 2019
1 check passed
Loading
@kubukoz
Copy link
Member

@kubukoz kubukoz commented Aug 26, 2019

y'all reading in my mind, I thought about this just a couple days ago... a very welcome change!

Loading

@SethTisue
Copy link
Member

@SethTisue SethTisue commented Dec 7, 2020

recent discussion at scala/scala#9303 has us wondering if this change was in fact safe. (which might affect decisions to make other such changes in the future)

Loading

@kubukoz
Copy link
Member

@kubukoz kubukoz commented Dec 7, 2020

Wow, took us long enough!

I can't remember any case in the ecosystem where this broke anything, but I would wager Parallel isn't that popular an abstraction in libraries, which could be why - everyone just updated cats and their sources and they were fine. (I think)

Loading

@SethTisue
Copy link
Member

@SethTisue SethTisue commented Dec 7, 2020

Perhaps y'all should mimaReportSignatureProblems := true and see whether there are too many false positives.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

8 participants