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

Update scalafmt-core to 3.8.4 #268

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ b73b3c3f8fcaaa70595cd267f7242b0a0c345039

# Scala Steward: Reformat with scalafmt 3.8.3
9cc844f181b6f41a327bbff0c18a8c6621532ef1

# Scala Steward: Reformat with scalafmt 3.8.4
803da131877e19253a99be2fba3cae6bfa784e7d
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.8.3
version = 3.8.4
maxColumn = 140
runner.dialect = scala3

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/ox/OxApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum ExitCode(val code: Int):
*
* - [[OxApp.Simple]] for applications which don't use command-line arguments
* - [[OxApp]] for applications which use command-line arguments
* - [[OxApp.WithEitherErrors]] to be able to unwrap `Either`s (see [[either.apply()]]) in the entry point's body. If case of failure,
* - [[OxApp.WithEitherErrors]] to be able to unwrap `Either` s (see [[either.apply()]]) in the entry point's body. If case of failure,
* the applications ends with an error
* - [[OxApp.WithErrorMode]] to report errors (which end the application) using other [[ErrorMode]]s
*
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/ox/channels/Channel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ end Sink
* There are three channel flavors:
*
* - rendezvous channels, where senders and receivers must meet to exchange values
* - buffered channels, where a given number of sent values might be buffered, before subsequent `send`s block
* - buffered channels, where a given number of sent values might be buffered, before subsequent `send` s block
* - unlimited channels, where an unlimited number of values might be buffered, hence `send` never blocks
*
* Channels can be created using the channel's companion object. A rendezvous channel is created using [[Channel.rendezvous]]. A buffered
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/scala/ox/either.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ object either:
error("The enclosing `either` call uses a different error type.\nIf it's explicitly typed, is the error type correct?")
case _ => error("`.ok()` can only be used within an `either` call.\nIs it present?")
}
end extension

/** Specialized extensions for Right & Left are necessary to prevent compile-time warning about unreachable cases in inlined pattern
* matches when call site has a specific type.
Expand All @@ -77,6 +78,7 @@ object either:
error("The enclosing `either` call uses a different error type.\nIf it's explicitly typed, is the error type correct?")
case _ => error("`.ok()` can only be used within an `either` call.\nIs it present?")
}
end extension

extension [A](inline t: Option[A])
/** Unwrap the value of the `Option`, short-circuiting the computation to the enclosing [[either]], in case this is a `None`. */
Expand All @@ -92,6 +94,7 @@ object either:
)
case _ => error("`.ok()` can only be used within an `either` call.\nIs it present?")
}
end extension

/** Specialized extensions for Some & None are necessary to prevent compile-time warning about unreachable cases in inlined pattern
* matches when call site has a specific type.
Expand All @@ -111,6 +114,7 @@ object either:
)
case _ => error("`.ok()` can only be used within an `either` call.\nIs it present?")
}
end extension

extension [E, A](inline f: Fork[Either[E, A]])
/** Join the fork and unwrap the value of its `Either` result, short-circuiting the computation to the enclosing [[either]], in case
Expand All @@ -120,6 +124,7 @@ object either:
* this method only when the fork is started using [[forkUnsupervised]] or [[forkCancellable]].
*/
transparent inline def ok(): A = f.join().ok()
end extension

extension [E](e: E)
/** Fail the computation, short-circuiting to the enclosing [[either]] block. */
Expand All @@ -129,10 +134,11 @@ object either:
case given boundary.Label[Either[Nothing, Nothing]] =>
error("The enclosing `either` call uses a different error type.\nIf it's explicitly typed, is the error type correct?")
}
end extension

extension [E <: Throwable, T](e: Either[E, T])
/** Unwrap the right-value of the `Either`, throwing the contained exception if this is a lef-value. For a variant which allows
* unwrapping `Either`s, propagates errors and doesn't throw exceptions, see [[apply]].
* unwrapping `Either` s, propagates errors and doesn't throw exceptions, see [[apply]].
*/
def orThrow: T = e match
case Right(value) => value
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/ox/flow/Flow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object Flow extends FlowCompanionOps with FlowCompanionIOOps with FlowCompanionR

//

/** Contains the logic for running a single flow stage. As part of `run`s implementation, previous flow stages might be run, either
/** Contains the logic for running a single flow stage. As part of `run` s implementation, previous flow stages might be run, either
* synchronously or asynchronously.
*/
trait FlowStage[+T]:
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/scala/ox/flow/FlowCompanionReactiveOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ trait FlowCompanionReactiveOps:

def onNext(t: T): Unit = channel.send(t)
def onError(t: Throwable): Unit = channel.error(t)
def onComplete(): Unit = channel.done()
)
def onComplete(): Unit = channel.done())
}.discard

repeatWhile:
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/ox/flow/FlowIOOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ trait FlowIOOps[+T]:
case chunk: T @unchecked =>
currentChunk = chunk.iterator
currentChunk.next() & 0xff // Convert to unsigned
end read

override def available: Int =
currentChunk.length
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/scala/ox/flow/FlowOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class FlowOps[+T]:
if taken == n then throw abortTake
)
catch case `abortTake` => () // done
end try

/** Transform the flow so that it emits elements as long as predicate `f` is satisfied (returns `true`). If `includeFirstFailing` is
* `true`, the flow will additionally emit the first element that failed the predicate. After that, the flow will complete as done.
Expand Down Expand Up @@ -764,8 +765,8 @@ class FlowOps[+T]:
// in special case when step == 1, we have to send the buffer immediately
if buffer.size == n then emit(buffer)
else
// step > n - we drop `step` elements and continue appending until buffer size is n
if buffer.size == step then buffer = buffer.drop(step)
// step > n - we drop `step` elements and continue appending until buffer size is n
if buffer.size == step then buffer = buffer.drop(step)
end if
)
// send the remaining elements, only if these elements were not yet sent
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/scala/ox/flow/FlowRunOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ trait FlowRunOps[+T]:
last.run(FlowEmit.fromInline: t =>
current match
case None => current = Some(t)
case Some(c) => current = Some(f(c, t))
)
case Some(c) => current = Some(f(c, t)))

current.getOrElse(throw new NoSuchElementException("cannot reduce an empty flow"))
end runReduce
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/ox/par.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def parLimit[T](parallelism: Int)(ts: Seq[() => T]): Seq[T] = parLimit(NoErrorMo

/** Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other
* computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type `E` in
* context `F`, and each computation must return an `F`-wrapped value.
* context `F`, and each computation must return an `F` -wrapped value.
*/
def par[E, F[_], T1, T2](em: ErrorMode[E, F])(t1: => F[T1], t2: => F[T2]): F[(T1, T2)] =
val r = par(em)(Vector(() => t1.asInstanceOf[F[Any]], () => t2.asInstanceOf[F[Any]]))
Expand All @@ -40,7 +40,7 @@ def par[E, F[_], T1, T2](em: ErrorMode[E, F])(t1: => F[T1], t2: => F[T2]): F[(T1

/** Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other
* computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type `E` in
* context `F`, and each computation must return an `F`-wrapped value.
* context `F`, and each computation must return an `F` -wrapped value.
*/
def par[E, F[_], T1, T2, T3](em: ErrorMode[E, F])(t1: => F[T1], t2: => F[T2], t3: => F[T3]): F[(T1, T2, T3)] =
val r = par(em)(Vector(() => t1.asInstanceOf[F[Any]], () => t2.asInstanceOf[F[Any]], () => t3.asInstanceOf[F[Any]]))
Expand All @@ -51,7 +51,7 @@ def par[E, F[_], T1, T2, T3](em: ErrorMode[E, F])(t1: => F[T1], t2: => F[T2], t3

/** Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other
* computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type `E` in
* context `F`, and each computation must return an `F`-wrapped value.
* context `F`, and each computation must return an `F` -wrapped value.
*/
def par[E, F[_], T1, T2, T3, T4](em: ErrorMode[E, F])(t1: => F[T1], t2: => F[T2], t3: => F[T3], t4: => F[T4]): F[(T1, T2, T3, T4)] =
val r = par(em)(
Expand All @@ -65,7 +65,7 @@ end par

/** Runs the given computations in parallel. If any fails because of an exception, or if any returns an application error, other
* computations are interrupted. Then, the exception is re-thrown, or the error value returned. Application errors must be of type `E` in
* context `F`, and each computation must return an `F`-wrapped value.
* context `F`, and each computation must return an `F` -wrapped value.
*/
def par[E, F[_], T](em: ErrorMode[E, F])(ts: Seq[() => F[T]]): F[Seq[T]] =
supervisedError(em) {
Expand All @@ -75,7 +75,7 @@ def par[E, F[_], T](em: ErrorMode[E, F])(ts: Seq[() => F[T]]): F[Seq[T]] =

/** Runs the given computations in parallel, with at most `parallelism` running in parallel at the same time. If any computation fails
* because of an exception, or if any returns an application error, other computations are interrupted. Then, the exception is re-thrown,
* or the error value returned. Application errors must be of type `E` in context `F`, and each computation must return an `F`-wrapped
* or the error value returned. Application errors must be of type `E` in context `F`, and each computation must return an `F` -wrapped
* value.
*/
def parLimit[E, F[_], T](em: ErrorMode[E, F])(parallelism: Int)(ts: Seq[() => F[T]]): F[Seq[T]] =
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/ox/race.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def raceSuccess[T](fs: Seq[() => T]): T = raceSuccess(NoErrorMode)(fs)

/** Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first
* exception / returns the first application error. Application errors must be of type `E` in context `F`, and each computation must return
* an `F`-wrapped value.
* an `F` -wrapped value.
*/
def raceSuccess[E, F[_], T](em: ErrorMode[E, F])(fs: Seq[() => F[T]]): F[T] =
unsupervised {
Expand Down Expand Up @@ -92,20 +92,20 @@ def raceSuccess[T](f1: => T, f2: => T, f3: => T, f4: => T): T = raceSuccess(List

/** Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first
* exception / returns the first application error. Application errors must be of type `E` in context `F`, and each computation must return
* an `F`-wrapped value.
* an `F` -wrapped value.
*/
def raceSuccess[E, F[_], T](em: ErrorMode[E, F])(f1: => F[T], f2: => F[T]): F[T] = raceSuccess(em)(List(() => f1, () => f2))

/** Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first
* exception / returns the first application error. Application errors must be of type `E` in context `F`, and each computation must return
* an `F`-wrapped value.
* an `F` -wrapped value.
*/
def raceSuccess[E, F[_], T](em: ErrorMode[E, F])(f1: => F[T], f2: => F[T], f3: => F[T]): F[T] =
raceSuccess(em)(List(() => f1, () => f2, () => f3))

/** Returns the result of the first computation to complete successfully, or if all fail / return an application error - throws the first
* exception / returns the first application error. Application errors must be of type `E` in context `F`, and each computation must return
* an `F`-wrapped value.
* an `F` -wrapped value.
*/
def raceSuccess[E, F[_], T](em: ErrorMode[E, F])(f1: => F[T], f2: => F[T], f3: => F[T], f4: => F[T]): F[T] =
raceSuccess(em)(List(() => f1, () => f2, () => f3, () => f4))
Expand Down
3 changes: 1 addition & 2 deletions core/src/test/scala/ox/ExceptionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ class ExceptionTest extends AnyFlatSpec with Matchers:
}
f.join()
}
catch
case e: Exception => addExceptionWithSuppressedTo(trail, e)
catch case e: Exception => addExceptionWithSuppressedTo(trail, e)

// either join() might throw the original exception (shouldn't be suppressed), or it might be interrupted before
// throwing (should be suppressed then)
Expand Down
13 changes: 5 additions & 8 deletions core/src/test/scala/ox/OxAppTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ class OxAppTest extends AnyFlatSpec with Matchers:
val sw = StringWriter()
val pw = PrintWriter(sw)
t.printStackTrace(pw)
stackTrace = sw.toString
)
stackTrace = sw.toString)
end Main31

Main31.main(Array.empty)
Expand All @@ -114,8 +113,7 @@ class OxAppTest extends AnyFlatSpec with Matchers:
val sw = StringWriter()
val pw = PrintWriter(sw)
t.printStackTrace(pw)
stackTrace = sw.toString
)
stackTrace = sw.toString)
end Main32

Main32.main(Array.empty)
Expand Down Expand Up @@ -224,8 +222,7 @@ class OxAppTest extends AnyFlatSpec with Matchers:
val sw = StringWriter()
val pw = PrintWriter(sw)
t.printStackTrace(pw)
stackTrace = sw.toString
)
stackTrace = sw.toString)
end Main70

Main70.main(Array.empty)
Expand Down Expand Up @@ -325,10 +322,10 @@ class OxAppTest extends AnyFlatSpec with Matchers:
val sw = StringWriter()
val pw = PrintWriter(sw)
t.printStackTrace(pw)
stackTrace = sw.toString
)
stackTrace = sw.toString)

override def handleError(e: FunException): ExitCode = ??? // should not get called!
end Main101

Main101.main(Array.empty)

Expand Down
3 changes: 1 addition & 2 deletions core/src/test/scala/ox/ParTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class ParTest extends AnyFlatSpec with Matchers:
throw new Exception("boom")
}
)
catch
case e: Exception if e.getMessage == "boom" => trail.add("catch")
catch case e: Exception if e.getMessage == "boom" => trail.add("catch")

// checking if the forks aren't left running
end try
Expand Down
1 change: 1 addition & 0 deletions core/src/test/scala/ox/RaceTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class RaceTest extends AnyFlatSpec with Matchers:
catch
case e: StackOverflowError => // the expected exception
flag.get() shouldBe false // because a fatal exception was thrown, the second computation should be interrupted
end try
}

"raceEither" should "return the first successful computation to complete" in {
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/scala/ox/flow/FlowIOOpsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ class FlowIOOpsTest extends AnyWordSpec with Matchers:
}
val sourceContent = "source.toFile test3 content"
filePath = folderPath.resolve("test-writefile3")
Flow.fromIterable(sourceContent.grouped(4).toList.map(chunkStr => Chunk.fromArray(chunkStr.getBytes)))
Flow
.fromIterable(sourceContent.grouped(4).toList.map(chunkStr => Chunk.fromArray(chunkStr.getBytes)))
.runToFile(filePath)

fileContent(filePath) shouldBe List(sourceContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extension [A](flow: Flow[A])
*/
def toReactiveStreamsPublisher(using Ox, BufferCapacity): Publisher[A] =
FlowAdapters.toPublisher(flow.toPublisher)
end extension

object FlowReactiveStreams:
/** This variant returns accepts an implementation of `org.reactivestreams.Publisher`, as opposed to `java.util.concurrent.Flow.Publisher`
Expand Down