Skip to content

Commit

Permalink
Update scalafmt to 2.3.2 (zio#2716)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostdogpr authored and adamgfraser committed Jan 25, 2020
1 parent ddf2ae9 commit 0f1dc5b
Show file tree
Hide file tree
Showing 38 changed files with 369 additions and 442 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "2.1.0"
version = "2.3.2"
maxColumn = 120
align = most
continuationIndent.defnSite = 2
Expand Down
6 changes: 4 additions & 2 deletions benchmarks/src/main/scala/zio/IODeepAttemptBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class IODeepAttemptBenchmark {

def descend(n: Int): Future[BigInt] =
if (n == depth) Future.failed(new Exception("Oh noes!"))
else if (n == halfway) descend(n + 1).recover { case _ => 50 } else descend(n + 1).map(_ + n)
else if (n == halfway) descend(n + 1).recover { case _ => 50 }
else descend(n + 1).map(_ + n)

Await.result(descend(0), Inf)
}
Expand Down Expand Up @@ -97,7 +98,8 @@ class IODeepAttemptBenchmark {
if (n == depth)
Future.exception(new Error("Oh noes!"))
else if (n == halfway)
descent(n + 1).handle { case _ => 50 } else descent(n + 1).map(_ + n)
descent(n + 1).handle { case _ => 50 }
else descent(n + 1).map(_ + n)

Await.result(descent(0))
}
Expand Down
10 changes: 6 additions & 4 deletions benchmarks/src/main/scala/zio/IOShallowAttemptBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class IOShallowAttemptBenchmark {
import scala.concurrent.duration.Duration.Inf

def throwup(n: Int): Future[BigInt] =
if (n == 0) throwup(n + 1) recover { case _ => 0 } else if (n == depth) Future(1)
if (n == 0) throwup(n + 1) recover { case _ => 0 }
else if (n == depth) Future(1)
else
throwup(n + 1).recover { case _ => 0 }
.flatMap(_ => Future.failed(new Exception("Oh noes!")))
Expand All @@ -51,11 +52,11 @@ class IOShallowAttemptBenchmark {
else
throwup(n + 1)
.exceptionally(_ => 0)
.thenCompose(_ => {
.thenCompose { _ =>
val f = new CompletableFuture[BigInt]()
f.completeExceptionally(new Exception("Oh noes!"))
f
})
}

throwup(0)
.get()
Expand Down Expand Up @@ -101,7 +102,8 @@ class IOShallowAttemptBenchmark {
def throwup(n: Int): Future[BigInt] =
if (n == 0) throwup(n + 1).rescue {
case _ => Future.value(0)
} else if (n == depth) Future(1)
}
else if (n == depth) Future(1)
else
throwup(n + 1).transform {
case Throw(_) => Future.value[BigInt](0)
Expand Down
7 changes: 3 additions & 4 deletions core-tests/jvm/src/test/scala-2.12/zio/StacktracesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,9 @@ object StackTracesSpec extends DefaultRunnableSpec {
_ <- ZIO.unit
_ <- ZIO.unit
} yield t)
.flatMap(
t =>
IO.trace
.map(tuple(t))
.flatMap(t =>
IO.trace
.map(tuple(t))
)
}

Expand Down
7 changes: 3 additions & 4 deletions core-tests/jvm/src/test/scala/zio/RTSSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ object RTSSpec extends ZIOBaseSpec {
exitLatch <- Promise.make[Nothing, Int]
bracketed = IO
.succeed(21)
.bracketExit(
(r: Int, exit: Exit[Any, Any]) =>
if (exit.interrupted) exitLatch.succeed(r)
else IO.die(new Error("Unexpected case"))
.bracketExit((r: Int, exit: Exit[Any, Any]) =>
if (exit.interrupted) exitLatch.succeed(r)
else IO.die(new Error("Unexpected case"))
)(a => startLatch.succeed(a) *> IO.never *> IO.succeed(1))
fiber <- bracketed.fork
startValue <- startLatch.await
Expand Down
4 changes: 1 addition & 3 deletions core-tests/shared/src/test/scala/zio/FunctionIOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,5 @@ object FunctionIOSpec extends ZIOBaseSpec {
val greaterThan0 = fromFunction[Int, Boolean](_ > 0)
val lessThan10 = fromFunction[Int, Boolean](_ < 10)

val thrower = effect[String, Int, Int] { case _: Throwable => "error" }(
_ => throw new Exception
)
val thrower = effect[String, Int, Int] { case _: Throwable => "error" }(_ => throw new Exception)
}
4 changes: 1 addition & 3 deletions core-tests/shared/src/test/scala/zio/ScheduleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,7 @@ object ScheduleSpec extends ZIOBaseSpec {
ok => ZIO.succeed(Right(ScheduleSuccess(ok)))
)
.retry(Schedule.spaced(2.seconds) && Schedule.recurs(1))
.catchAll(
error => ZIO.succeed(Left(ScheduleFailure(error.message)))
)
.catchAll(error => ZIO.succeed(Left(ScheduleFailure(error.message))))

val expected = Right(ScheduleSuccess("Ok"))
assertM(foo("Ok"))(equalTo(expected))
Expand Down
8 changes: 2 additions & 6 deletions core-tests/shared/src/test/scala/zio/SemaphoreSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ object SemaphoreSpec extends ZIOBaseSpec {
} yield assert(available)(forall(isLessThan(20L)))
},
testM("`acquireN`s can be parallel with `releaseN`s") {
offsettingWithPermits(
(s, permits) => IO.foreach(permits)(s.withPermits(_)(IO.unit)).unit
)
offsettingWithPermits((s, permits) => IO.foreach(permits)(s.withPermits(_)(IO.unit)).unit)
},
testM("individual `acquireN`s can be parallel with individual `releaseN`s") {
offsettingWithPermits(
(s, permits) => IO.foreachPar(permits)(s.withPermits(_)(IO.unit)).unit
)
offsettingWithPermits((s, permits) => IO.foreachPar(permits)(s.withPermits(_)(IO.unit)).unit)
},
testM("semaphores and fibers play ball together") {
val n = 1L
Expand Down
25 changes: 9 additions & 16 deletions core-tests/shared/src/test/scala/zio/ZIOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1566,8 +1566,8 @@ object ZIOSpec extends ZIOBaseSpec {
log = makeLogger(ref)
f <- ZIO
.bracket(
ZIO.bracket(ZIO.unit)(_ => log("start 1") *> clock.sleep(10.millis) *> log("release 1"))(
_ => ZIO.unit
ZIO.bracket(ZIO.unit)(_ => log("start 1") *> clock.sleep(10.millis) *> log("release 1"))(_ =>
ZIO.unit
)
)(_ => log("start 2") *> clock.sleep(10.millis) *> log("release 2"))(_ => ZIO.unit)
.fork
Expand Down Expand Up @@ -2116,9 +2116,7 @@ object ZIOSpec extends ZIOBaseSpec {
for {
promise <- Promise.make[Nothing, Unit]
fiber <- IO
.bracketExit(promise.succeed(()) *> IO.never *> IO.succeed(1))(
(_, _: Exit[Any, Any]) => IO.unit
)(
.bracketExit(promise.succeed(()) *> IO.never *> IO.succeed(1))((_, _: Exit[Any, Any]) => IO.unit)(
_ => IO.unit: IO[Nothing, Unit]
)
.fork
Expand Down Expand Up @@ -2156,10 +2154,7 @@ object ZIOSpec extends ZIOBaseSpec {
for {
done <- Promise.make[Nothing, Unit]
fiber <- withLatch { release =>
IO.bracketExit(IO.unit)((_, _: Exit[Any, Any]) => done.succeed(()))(
_ => release *> IO.never
)
.fork
IO.bracketExit(IO.unit)((_, _: Exit[Any, Any]) => done.succeed(()))(_ => release *> IO.never).fork
}

_ <- fiber.interrupt
Expand All @@ -2185,8 +2180,8 @@ object ZIOSpec extends ZIOBaseSpec {
p2 <- Promise.make[Nothing, Unit]
p3 <- Promise.make[Nothing, Unit]
s <- IO
.bracketForkExit(p1.succeed(()) *> p2.await)((_, _: Exit[Any, Any]) => p3.await)(
_ => IO.unit: IO[Nothing, Unit]
.bracketForkExit(p1.succeed(()) *> p2.await)((_, _: Exit[Any, Any]) => p3.await)(_ =>
IO.unit: IO[Nothing, Unit]
)
.fork
_ <- p1.await
Expand Down Expand Up @@ -2223,9 +2218,7 @@ object ZIOSpec extends ZIOBaseSpec {
for {
done <- Promise.make[Nothing, Unit]
fiber <- withLatch { release =>
IO.bracketForkExit(IO.unit)((_, _: Exit[Any, Any]) => done.succeed(()))(
_ => release *> IO.never
)
IO.bracketForkExit(IO.unit)((_, _: Exit[Any, Any]) => done.succeed(()))(_ => release *> IO.never)
.fork
}

Expand Down Expand Up @@ -2504,8 +2497,8 @@ object ZIOSpec extends ZIOBaseSpec {
for {
ref <- Ref.make(Option.empty[internal.Executor])
exec = internal.Executor.fromExecutionContext(100)(scala.concurrent.ExecutionContext.Implicits.global)
_ <- withLatch(
release => IO.descriptor.map(_.executor).flatMap(e => ref.set(Some(e)) *> release).fork.lock(exec)
_ <- withLatch(release =>
IO.descriptor.map(_.executor).flatMap(e => ref.set(Some(e)) *> release).fork.lock(exec)
)
v <- ref.get
} yield v.contains(exec)
Expand Down
12 changes: 5 additions & 7 deletions core-tests/shared/src/test/scala/zio/ZManagedSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1310,12 +1310,10 @@ object ZManagedSpec extends ZIOBaseSpec {
effects <- Ref.make(0)
countDown <- countDownLatch(n + 1)
reserveLatch <- Promise.make[Nothing, Unit]
baseRes = ZManaged.make(effects.update(_ + 1) *> countDown *> reserveLatch.await)(
_ => ZIO.unit
)
res = f(baseRes)
_ <- res.use_(ZIO.unit).fork *> countDown
count <- effects.get
_ <- reserveLatch.succeed(())
baseRes = ZManaged.make(effects.update(_ + 1) *> countDown *> reserveLatch.await)(_ => ZIO.unit)
res = f(baseRes)
_ <- res.use_(ZIO.unit).fork *> countDown
count <- effects.get
_ <- reserveLatch.succeed(())
} yield assert(count)(equalTo(n))
}
13 changes: 6 additions & 7 deletions core-tests/shared/src/test/scala/zio/stm/ZSTMSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,12 @@ object ZSTMSpec extends ZIOBaseSpec {
for {
tvar <- TRef.makeCommit(0)
fiber <- IO.forkAll(
(0 to 20).map(
i =>
(for {
v <- tvar.get
_ <- STM.check(v == i)
_ <- tvar.update(_ + 1)
} yield ()).commit
(0 to 20).map(i =>
(for {
v <- tvar.get
_ <- STM.check(v == i)
_ <- tvar.update(_ + 1)
} yield ()).commit
)
)
_ <- fiber.join
Expand Down
21 changes: 9 additions & 12 deletions core/shared/src/main/scala/zio/Chunk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,9 @@ sealed trait Chunk[+A] { self =>
i += 1
}

array.map(
array =>
if (array == null) Chunk.empty
else Chunk.fromArray(array)
array.map(array =>
if (array == null) Chunk.empty
else Chunk.fromArray(array)
)
}

Expand Down Expand Up @@ -942,10 +941,9 @@ object Chunk {
i += 1
}

dest.map(
array =>
if (array == null) Chunk.empty
else Chunk.Slice(Chunk.Arr(array), 0, j)
dest.map(array =>
if (array == null) Chunk.empty
else Chunk.Slice(Chunk.Arr(array), 0, j)
)
}

Expand Down Expand Up @@ -1012,10 +1010,9 @@ object Chunk {
i += 1
}

dest.map(
array =>
if (array == null) Chunk.empty
else Chunk.Slice(Chunk.Arr(array), 0, j)
dest.map(array =>
if (array == null) Chunk.empty
else Chunk.Slice(Chunk.Arr(array), 0, j)
)
}

Expand Down
15 changes: 7 additions & 8 deletions core/shared/src/main/scala/zio/FunctionIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ object FunctionIO extends Serializable {

case _ =>
lazy val loop: FunctionIO[E, A, A] =
FunctionIO.fromFunctionM(
(a: A) => check.run(a).flatMap((b: Boolean) => if (b) body.run(a).flatMap(loop.run) else IO.succeed(a))
FunctionIO.fromFunctionM((a: A) =>
check.run(a).flatMap((b: Boolean) => if (b) body.run(a).flatMap(loop.run) else IO.succeed(a))
)

loop
Expand Down Expand Up @@ -394,12 +394,11 @@ object FunctionIO extends Serializable {
})

case _ =>
FunctionIO.fromFunctionM(
(a: A) =>
for {
b <- l.run(a)
c <- r.run(a)
} yield f(b, c)
FunctionIO.fromFunctionM((a: A) =>
for {
b <- l.run(a)
c <- r.run(a)
} yield f(b, c)
)
}

Expand Down
Loading

0 comments on commit 0f1dc5b

Please sign in to comment.