Skip to content

Commit eff015e

Browse files
committed
Fix a build for Scala 2.12
1 parent 6054ce3 commit eff015e

3 files changed

Lines changed: 30 additions & 29 deletions

File tree

.scalafmt.conf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
version = "3.8.6"
2-
runner.dialect = scala213
2+
runner.dialect = scala213
3+
4+
fileOverride {
5+
"glob:**/src/main/scala-3/**" {
6+
runner.dialect = scala3
7+
}
8+
}

build.sbt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import Dependencies._
22

33
name := "random"
4-
54
organization := "com.evolution"
6-
75
homepage := Some(url("https://github.com/evolution-gaming/random"))
8-
96
startYear := Some(2019)
10-
117
organizationName := "Evolution"
12-
138
organizationHomepage := Some(url("https://evolution.com"))
149

1510
scalaVersion := crossScalaVersions.value.head
16-
1711
crossScalaVersions := Seq("2.13.11", "2.12.18", "3.3.5")
18-
1912
versionPolicyIntention := Compatibility.BinaryCompatible
2013

14+
scalacOptions += {
15+
if (scalaVersion.value startsWith "2.12") "-Ywarn-unused-import"
16+
else "-Wunused:imports"
17+
}
18+
2119
Compile / unmanagedSourceDirectories += {
2220
if (scalaVersion.value startsWith "2")
2321
sourceDirectory.value / "main" / "scala-2"

src/main/scala-3/com/evolutiongaming/random/Random.scala

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object Random {
1818

1919
def apply[F[_]](using F: Random[F]): Random[F] = F
2020

21-
extension [F[_]](self: Random[F]){
21+
extension [F[_]](self: Random[F]) {
2222
def mapK[G[_]](f: F ~> G): Random[G] = new Random[G] {
2323
def int = f(self.int)
2424
def long = f(self.long)
@@ -27,7 +27,6 @@ object Random {
2727
}
2828
}
2929

30-
3130
type SeedT[A] = cats.data.StateT[Id, Seed, A]
3231

3332
object SeedT {
@@ -41,7 +40,7 @@ object Random {
4140
def next(bits: Int): SeedT[Int] = {
4241
SeedT { seed =>
4342
val r = (seed >>> (48 - bits)).toInt
44-
val s1 = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)
43+
val s1 = (seed * 0x5deece66dL + 0xbL) & ((1L << 48) - 1)
4544
(s1, r)
4645
}
4746
}
@@ -53,36 +52,32 @@ object Random {
5352
def long = {
5453
for
5554
a0 <- next(32)
56-
a1 = a0.toLong << 32
55+
a1 = a0.toLong << 32
5756
a2 <- next(32)
58-
yield
59-
a1 + a2
57+
yield a1 + a2
6058
}
6159

6260
def float = {
63-
for
64-
a <- next(24)
65-
yield
66-
a / floatUnit
61+
for a <- next(24)
62+
yield a / floatUnit
6763
}
6864

6965
def double = {
7066
for
7167
a0 <- next(26)
72-
a1 = a0.toLong << 27
68+
a1 = a0.toLong << 27
7369
a2 <- next(27)
74-
yield
75-
(a1 + a2) * doubleUnit
70+
yield (a1 + a2) * doubleUnit
7671
}
7772
}
7873
}
7974

80-
81-
def apply[A](f: Seed => (Seed, A)): SeedT[A] = cats.data.StateT[Id, Seed, A] { seed => f(seed) }
75+
def apply[A](f: Seed => (Seed, A)): SeedT[A] =
76+
cats.data.StateT[Id, Seed, A] { seed => f(seed) }
8277
}
8378

84-
85-
final case class State(seed: Seed, random: Random[SeedT] = SeedT.Random) extends Random[State.Type] {
79+
final case class State(seed: Seed, random: Random[SeedT] = SeedT.Random)
80+
extends Random[State.Type] {
8681

8782
private def apply[A](stateT: SeedT[A]) = {
8883
val (seed1, a) = stateT.run(seed)
@@ -99,11 +94,13 @@ object Random {
9994

10095
type Type[A] = (State, A)
10196

102-
def fromClock[F[_]: Clock: FlatMap](random: Random[SeedT] = SeedT.Random): F[State] = {
103-
for
104-
nanos <- Clock[F].nanos
97+
def fromClock[F[_]: Clock: FlatMap](
98+
random: Random[SeedT] = SeedT.Random
99+
): F[State] = {
100+
for nanos <- Clock[F].nanos
105101
yield
106-
val seed = (nanos ^ 3447679086515839964L ^ 0x5DEECE66DL) & ((1L << 48) - 1)
102+
val seed =
103+
(nanos ^ 3447679086515839964L ^ 0x5deece66dL) & ((1L << 48) - 1)
107104
apply(seed, random)
108105
}
109106
}

0 commit comments

Comments
 (0)