Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d30f739

Browse files
author
Cristian Cantarero
committedNov 27, 2024·
feat: migrate to scala 3
1 parent cafdda3 commit d30f739

15 files changed

+61
-94
lines changed
 

‎build.sbt

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sbtcrossproject.CrossPlugin.autoImport.crossProject
2-
import _root_.org.typelevel.sbt.tpolecat.TpolecatPlugin.autoImport._
32
import _root_.org.typelevel.scalacoptions.ScalacOptions
43

54
lazy val scalaVersion213 = "2.13.13"
@@ -83,10 +82,6 @@ val docs = project
8382
.dependsOn(coreJVM, mtlJVM)
8483
.enablePlugins(MicrositesPlugin, BuildInfoPlugin)
8584
.settings(
86-
scalaVersion := scalaVersion213,
87-
addCompilerPlugin(
88-
"org.typelevel" %% "kind-projector" % "0.13.3" cross CrossVersion.full
89-
),
9085
tpolecatExcludeOptions ++= ScalacOptions.warnUnusedOptions,
9186
tpolecatExcludeOptions += ScalacOptions.warnNonUnitStatement,
9287
crossScalaVersions := Nil,

‎modules/core/shared/src/main/scala/retry/Fibonacci.scala

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package retry
22

33
object Fibonacci {
44
def fibonacci(n: Int): Long = {
5-
if (n > 0)
6-
fib(n)._1
7-
else
8-
0
5+
if n > 0 then fib(n)._1
6+
else 0
97
}
108

119
// "Fast doubling" Fibonacci algorithm.
@@ -16,9 +14,7 @@ object Fibonacci {
1614
val (a, b) = fib(m / 2)
1715
val c = a * (b * 2 - a)
1816
val d = a * a + b * b
19-
if (n % 2 == 0)
20-
(c, d)
21-
else
22-
(d, c + d)
17+
if n % 2 == 0 then (c, d)
18+
else (d, c + d)
2319
}
2420
}

‎modules/core/shared/src/main/scala/retry/RetryPolicies.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package retry
33
import java.util.concurrent.TimeUnit
44

55
import cats.Applicative
6-
import cats.syntax.functor._
7-
import cats.syntax.show._
8-
import retry.PolicyDecision._
6+
import cats.syntax.functor.*
7+
import cats.syntax.show.*
8+
import retry.PolicyDecision.*
99

1010
import scala.concurrent.duration.{Duration, FiniteDuration}
1111
import scala.util.Random
@@ -66,7 +66,7 @@ object RetryPolicies {
6666
def limitRetries[M[_]: Applicative](maxRetries: Int): RetryPolicy[M] =
6767
RetryPolicy.liftWithShow(
6868
{ status =>
69-
if (status.retriesSoFar >= maxRetries) {
69+
if status.retriesSoFar >= maxRetries then {
7070
GiveUp
7171
} else {
7272
DelayAndRetry(Duration.Zero)
@@ -125,7 +125,7 @@ object RetryPolicies {
125125
def decideNextRetry(status: RetryStatus): M[PolicyDecision] =
126126
policy.decideNextRetry(status).map {
127127
case r @ DelayAndRetry(delay) =>
128-
if (delay > threshold) GiveUp else r
128+
if delay > threshold then GiveUp else r
129129
case GiveUp => GiveUp
130130
}
131131

@@ -145,7 +145,7 @@ object RetryPolicies {
145145
def decideNextRetry(status: RetryStatus): M[PolicyDecision] =
146146
policy.decideNextRetry(status).map {
147147
case r @ DelayAndRetry(delay) =>
148-
if (status.cumulativeDelay + delay >= threshold) GiveUp else r
148+
if status.cumulativeDelay + delay >= threshold then GiveUp else r
149149
case GiveUp => GiveUp
150150
}
151151

‎modules/core/shared/src/main/scala/retry/RetryPolicy.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package retry
22

33
import cats.{Apply, Applicative, Monad, Functor}
44
import cats.kernel.BoundedSemilattice
5-
import retry.PolicyDecision._
5+
import retry.PolicyDecision.*
66

77
import scala.concurrent.duration.Duration
88
import scala.concurrent.duration.FiniteDuration
99
import cats.arrow.FunctionK
10-
import cats.implicits._
10+
import cats.implicits.*
1111
import cats.Show
1212

1313
case class RetryPolicy[M[_]](

‎modules/core/shared/src/main/scala/retry/package.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cats.{Monad, MonadError}
2-
import cats.syntax.apply._
3-
import cats.syntax.functor._
4-
import cats.syntax.flatMap._
2+
import cats.syntax.apply.*
3+
import cats.syntax.functor.*
4+
import cats.syntax.flatMap.*
55

66
import scala.concurrent.duration.FiniteDuration
77

‎modules/core/shared/src/test/scala/retry/PackageObjectSuite.scala

+13-25
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import cats.Id
44
import munit.FunSuite
55

66
import scala.collection.mutable.ArrayBuffer
7-
import scala.concurrent.duration._
7+
import scala.concurrent.duration.*
88

99
class PackageObjectSuite extends FunSuite {
1010
type StringOr[A] = Either[String, A]
@@ -118,10 +118,8 @@ class PackageObjectSuite extends FunSuite {
118118
onError
119119
) {
120120
attempts = attempts + 1
121-
if (attempts < 3)
122-
Left("one more time")
123-
else
124-
Right("yay")
121+
if attempts < 3 then Left("one more time")
122+
else Right("yay")
125123
}
126124

127125
assertEquals(finalResult, Right("yay"))
@@ -141,10 +139,8 @@ class PackageObjectSuite extends FunSuite {
141139
onError
142140
) {
143141
attempts = attempts + 1
144-
if (attempts < 3)
145-
Left("one more time")
146-
else
147-
Left("nope")
142+
if attempts < 3 then Left("one more time")
143+
else Left("nope")
148144
}
149145

150146
assertEquals(finalResult, Left("nope"))
@@ -208,10 +204,8 @@ class PackageObjectSuite extends FunSuite {
208204
onError
209205
) {
210206
attempts = attempts + 1
211-
if (attempts < 3)
212-
Left("one more time")
213-
else
214-
Right("yay")
207+
if attempts < 3 then Left("one more time")
208+
else Right("yay")
215209
}
216210

217211
assertEquals(finalResult, Right("yay"))
@@ -273,10 +267,8 @@ class PackageObjectSuite extends FunSuite {
273267
onError
274268
) {
275269
attempts = attempts + 1
276-
if (attempts < 3)
277-
Left("one more time")
278-
else
279-
Right("yay")
270+
if attempts < 3 then Left("one more time")
271+
else Right("yay")
280272
}
281273

282274
assertEquals(finalResult, Right("yay"))
@@ -298,10 +290,8 @@ class PackageObjectSuite extends FunSuite {
298290
onError
299291
) {
300292
attempts = attempts + 1
301-
if (attempts < 3)
302-
Left("one more time")
303-
else
304-
Left("nope")
293+
if attempts < 3 then Left("one more time")
294+
else Left("nope")
305295
}
306296

307297
assertEquals(finalResult, Left("nope"))
@@ -418,10 +408,8 @@ class PackageObjectSuite extends FunSuite {
418408
onError
419409
) {
420410
attempts = attempts + 1
421-
if (attempts < 3)
422-
Left("one more time")
423-
else
424-
Right("yay")
411+
if attempts < 3 then Left("one more time")
412+
else Right("yay")
425413
}
426414

427415
assertEquals(finalResult, Right("yay"))

‎modules/core/shared/src/test/scala/retry/RetryPoliciesSuite.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package retry
22

33
import java.util.concurrent.TimeUnit
44

5-
import retry.RetryPolicies._
5+
import retry.RetryPolicies.*
66
import cats.Id
77
import org.scalacheck.{Arbitrary, Gen}
88
import org.scalacheck.Prop.forAll
99
import munit.ScalaCheckSuite
1010
import retry.PolicyDecision.{DelayAndRetry, GiveUp}
1111

12-
import scala.concurrent.duration._
12+
import scala.concurrent.duration.*
1313
import munit.Location
1414

1515
class RetryPoliciesSuite extends ScalaCheckSuite {
@@ -137,7 +137,7 @@ class RetryPoliciesSuite extends ScalaCheckSuite {
137137
arbitraryCumulativeDelay,
138138
arbitraryPreviousDelay
139139
)
140-
for (_ <- 1 to 1000) {
140+
for _ <- 1 to 1000 do {
141141
val verdict = policy.decideNextRetry(status)
142142
val delay = verdict.asInstanceOf[PolicyDecision.DelayAndRetry].delay
143143
assert(delay >= Duration.Zero)
@@ -170,7 +170,7 @@ class RetryPoliciesSuite extends ScalaCheckSuite {
170170
val limit = 500
171171
val verdict =
172172
limitRetries[Id](limit).decideNextRetry(status)
173-
if (status.retriesSoFar < limit) {
173+
if status.retriesSoFar < limit then {
174174
verdict == PolicyDecision.DelayAndRetry(Duration.Zero)
175175
} else {
176176
verdict == PolicyDecision.GiveUp

‎modules/core/shared/src/test/scala/retry/RetryPolicyLawsSuite.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package retry
22

3-
import cats.instances.all._
3+
import cats.instances.all.*
44
import cats.{Eq, Monoid, Id}
55
import cats.kernel.laws.discipline.BoundedSemilatticeTests
66
import munit.DisciplineSuite
77
import org.scalacheck.{Arbitrary, Cogen, Gen}
88
import org.scalacheck.Prop.*
99

10-
import scala.concurrent.duration._
10+
import scala.concurrent.duration.*
1111
import cats.laws.discipline.ExhaustiveCheck
1212
import cats.laws.discipline.eq.catsLawsEqForFn1Exhaustive
1313
import cats.arrow.FunctionK

‎modules/core/shared/src/test/scala/retry/RetryPolicySuite.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package retry
22

33
import cats.Id
4-
import cats.syntax.semigroup._
4+
import cats.syntax.semigroup.*
55
import munit.FunSuite
66

7-
import scala.concurrent.duration._
7+
import scala.concurrent.duration.*
88

99
class RetryPolicySuite extends FunSuite {
1010

‎modules/core/shared/src/test/scala/retry/SyntaxSuite.scala

+8-14
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package retry
22

33
import cats.Id
44
import munit.FunSuite
5-
import retry.syntax.all._
5+
import retry.syntax.all.*
66

77
import scala.collection.mutable.ArrayBuffer
8-
import scala.concurrent.duration._
8+
import scala.concurrent.duration.*
99

1010
class SyntaxSuite extends FunSuite {
1111
type StringOr[A] = Either[String, A]
@@ -96,10 +96,8 @@ class SyntaxSuite extends FunSuite {
9696

9797
def action: StringOr[String] = {
9898
incrementAttempts()
99-
if (attempts < 3)
100-
Left("one more time")
101-
else
102-
Right("yay")
99+
if attempts < 3 then Left("one more time")
100+
else Right("yay")
103101
}
104102

105103
val finalResult: StringOr[String] =
@@ -125,10 +123,8 @@ class SyntaxSuite extends FunSuite {
125123

126124
def action: StringOr[Nothing] = {
127125
incrementAttempts()
128-
if (attempts < 3)
129-
Left("one more time")
130-
else
131-
Left("nope")
126+
if attempts < 3 then Left("one more time")
127+
else Left("nope")
132128
}
133129

134130
val finalResult =
@@ -186,10 +182,8 @@ class SyntaxSuite extends FunSuite {
186182

187183
def action: StringOr[String] = {
188184
incrementAttempts()
189-
if (attempts < 3)
190-
Left("one more time")
191-
else
192-
Right("yay")
185+
if attempts < 3 then Left("one more time")
186+
else Right("yay")
193187
}
194188

195189
val finalResult: StringOr[String] =

‎modules/docs/src/main/scala/util/FlakyHttpClient.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ case class FlakyHttpClient() {
77
private var i = 0
88

99
def getCatGif(): String = {
10-
if (i > 3) {
10+
if i > 3 then {
1111
"cute cat gets sleepy and falls asleep"
1212
} else {
1313
i = i + 1
@@ -16,9 +16,9 @@ case class FlakyHttpClient() {
1616
}
1717

1818
def getRecordDetails(id: String): String = {
19-
if (i > 3) {
19+
if i > 3 then {
2020
"got some sweet details"
21-
} else if (i == 0) {
21+
} else if i == 0 then {
2222
i = i + 1
2323
throw new TimeoutException("Timed out getting details")
2424
} else {

‎modules/docs/src/main/scala/util/LoadedDie.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ case class LoadedDie(rolls: Int*) {
55

66
def roll(): Int = {
77
i = i + 1
8-
if (i >= rolls.length) {
8+
if i >= rolls.length then {
99
i = 0
1010
}
1111
rolls(i)

‎modules/mtl/shared/src/main/scala/retry/mtl/package.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package retry
22

33
import cats.Monad
44
import cats.mtl.Handle
5-
import cats.syntax.apply._
6-
import cats.syntax.flatMap._
7-
import cats.syntax.functor._
5+
import cats.syntax.apply.*
6+
import cats.syntax.flatMap.*
7+
import cats.syntax.functor.*
88

99
package object mtl {
1010

‎modules/mtl/shared/src/test/scala/retry/mtl/PackageObjectSuite.scala

+7-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import munit.FunSuite
55
import retry.{RetryDetails, RetryPolicies, Sleep}
66

77
import scala.collection.mutable.ArrayBuffer
8-
import scala.concurrent.duration._
8+
import scala.concurrent.duration.*
99

1010
class PackageObjectSuite extends FunSuite {
1111
type ErrorOr[A] = Either[Throwable, A]
@@ -49,10 +49,8 @@ class PackageObjectSuite extends FunSuite {
4949
retryingOnSomeErrors(policy, isWorthRetrying, onMtlError) {
5050
attempts = attempts + 1
5151

52-
if (attempts < 3)
53-
EitherT.leftT[ErrorOr, String]("one more time")
54-
else
55-
EitherT.pure[ErrorOr, String]("yay")
52+
if attempts < 3 then EitherT.leftT[ErrorOr, String]("one more time")
53+
else EitherT.pure[ErrorOr, String]("yay")
5654
}
5755

5856
assertEquals(finalResult.value, Right(Right("yay")))
@@ -73,10 +71,8 @@ class PackageObjectSuite extends FunSuite {
7371
retryingOnSomeErrors(policy, isWorthRetrying, onMtlError) {
7472
attempts = attempts + 1
7573

76-
if (attempts < 3)
77-
EitherT.leftT[ErrorOr, String]("one more time")
78-
else
79-
EitherT.leftT[ErrorOr, String]("nope")
74+
if attempts < 3 then EitherT.leftT[ErrorOr, String]("one more time")
75+
else EitherT.leftT[ErrorOr, String]("nope")
8076
}
8177

8278
assertEquals(finalResult.value, Right(Left("nope")))
@@ -138,10 +134,8 @@ class PackageObjectSuite extends FunSuite {
138134
val finalResult = retryingOnAllErrors(policy, onMtlError) {
139135
attempts = attempts + 1
140136

141-
if (attempts < 3)
142-
EitherT.leftT[ErrorOr, String]("one more time")
143-
else
144-
EitherT.pure[ErrorOr, String]("yay")
137+
if attempts < 3 then EitherT.leftT[ErrorOr, String]("one more time")
138+
else EitherT.pure[ErrorOr, String]("yay")
145139
}
146140

147141
assertEquals(finalResult.value, Right(Right("yay")))

‎modules/mtl/shared/src/test/scala/retry/mtl/SyntaxSuite.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package retry.mtl
33
import cats.data.EitherT
44
import cats.data.EitherT.catsDataMonadErrorFForEitherT
55
import munit.FunSuite
6-
import retry.syntax.all._
7-
import retry.mtl.syntax.all._
6+
import retry.syntax.all.*
7+
import retry.mtl.syntax.all.*
88
import retry.{RetryDetails, RetryPolicies, RetryPolicy, Sleep}
99

1010
import scala.collection.mutable.ArrayBuffer
11-
import scala.concurrent.duration._
11+
import scala.concurrent.duration.*
1212

1313
class SyntaxSuite extends FunSuite {
1414
type ErrorOr[A] = Either[Throwable, A]

0 commit comments

Comments
 (0)
Please sign in to comment.