From 6505860a9b20d89531396a9ad551826ce9dcc8b3 Mon Sep 17 00:00:00 2001 From: Jon Pretty Date: Mon, 11 Nov 2024 11:29:26 +0100 Subject: [PATCH] Update indentation style --- src/core/contingency-core.scala | 47 ++++++++++----------- src/core/contingency.Accrue.scala | 4 +- src/core/contingency.AccrueTactic.scala | 12 +++--- src/core/contingency.AmalgamateTactic.scala | 4 +- src/core/contingency.AttemptTactic.scala | 4 +- src/core/contingency.Contingency.scala | 43 +++++++++---------- src/core/contingency.EitherTactic.scala | 4 +- src/core/contingency.Foci.scala | 6 +-- src/core/contingency.OptionalTactic.scala | 2 +- src/core/contingency.ThrowTactic.scala | 2 +- src/core/contingency.Track.scala | 4 +- src/core/contingency.TrackTactic.scala | 10 ++--- 12 files changed, 70 insertions(+), 72 deletions(-) diff --git a/src/core/contingency-core.scala b/src/core/contingency-core.scala index 857e3d8..8019f62 100644 --- a/src/core/contingency-core.scala +++ b/src/core/contingency-core.scala @@ -54,14 +54,14 @@ package strategies: given realm: Realm = realm"contingency" def raise[SuccessType, ErrorType <: Exception: Recoverable into SuccessType] - (error: Diagnostics ?=> ErrorType) - (using tactic: Tactic[ErrorType]) + (error: Diagnostics ?=> ErrorType) + (using tactic: Tactic[ErrorType]) : SuccessType = tactic.record(error) ErrorType.recover(error(using tactic.diagnostics)) def raise[SuccessType, ErrorType <: Exception: Tactic] - (error: Diagnostics ?=> ErrorType, ersatz: => SuccessType) + (error: Diagnostics ?=> ErrorType, ersatz: => SuccessType) : SuccessType = ErrorType.record(error) ersatz @@ -70,7 +70,7 @@ def abort[SuccessType, ErrorType <: Exception: Tactic](error: Diagnostics ?=> Er ErrorType.abort(error) def safely[ErrorType <: Exception](using DummyImplicit)[SuccessType] - (block: (Diagnostics, OptionalTactic[ErrorType, SuccessType]) ?=> CanThrow[Exception] ?=> + (block: (Diagnostics, OptionalTactic[ErrorType, SuccessType]) ?=> CanThrow[Exception] ?=> SuccessType) : Optional[SuccessType] = @@ -79,8 +79,7 @@ def safely[ErrorType <: Exception](using DummyImplicit)[SuccessType] catch case error: Exception => Unset def unsafely[ErrorType <: Exception](using DummyImplicit)[SuccessType] - (block: Unsafe ?=> ThrowTactic[ErrorType, SuccessType] ?=> CanThrow[Exception] ?=> - SuccessType) + (block: Unsafe ?=> ThrowTactic[ErrorType, SuccessType] ?=> CanThrow[Exception] ?=> SuccessType) : SuccessType = boundary: label ?=> @@ -88,14 +87,14 @@ def unsafely[ErrorType <: Exception](using DummyImplicit)[SuccessType] block(using Unsafe)(using ThrowTactic()) def throwErrors[ErrorType <: Exception](using CanThrow[ErrorType])[SuccessType] - (block: ThrowTactic[ErrorType, SuccessType] ?=> SuccessType) + (block: ThrowTactic[ErrorType, SuccessType] ?=> SuccessType) : SuccessType = block(using ThrowTactic()) def capture[ErrorType <: Exception](using DummyImplicit)[SuccessType] - (block: EitherTactic[ErrorType, SuccessType] ?=> SuccessType) - (using Tactic[ExpectationError[SuccessType]], Diagnostics) + (block: EitherTactic[ErrorType, SuccessType] ?=> SuccessType) + (using Tactic[ExpectationError[SuccessType]], Diagnostics) : ErrorType = val value: Either[ErrorType, SuccessType] = boundary: label ?=> Right(block(using EitherTactic(label))) @@ -105,22 +104,22 @@ def capture[ErrorType <: Exception](using DummyImplicit)[SuccessType] case Right(value) => abort(ExpectationError(value)) def attempt[ErrorType <: Exception](using DummyImplicit)[SuccessType] - (block: AttemptTactic[ErrorType, SuccessType] ?=> SuccessType) - (using Diagnostics) + (block: AttemptTactic[ErrorType, SuccessType] ?=> SuccessType) + (using Diagnostics) : Attempt[SuccessType, ErrorType] = boundary: label ?=> Attempt.Success(block(using AttemptTactic(label))) def amalgamate[ErrorType <: Exception](using DummyImplicit)[SuccessType] - (block: AmalgamateTactic[ErrorType, SuccessType] ?=> SuccessType) - (using Diagnostics) + (block: AmalgamateTactic[ErrorType, SuccessType] ?=> SuccessType) + (using Diagnostics) : SuccessType | ErrorType = boundary: label ?=> block(using AmalgamateTactic(label)) def abandonment[ErrorType <: Error](using Quotes, Realm)[SuccessType] - (block: Diagnostics ?=> AbandonTactic[ErrorType, SuccessType] ?=> SuccessType) + (block: Diagnostics ?=> AbandonTactic[ErrorType, SuccessType] ?=> SuccessType) : SuccessType = given AbandonTactic[ErrorType, SuccessType]() @@ -135,8 +134,8 @@ infix type mitigates [ErrorType <: Exception, ErrorType2 <: Exception] = infix type tracks [ResultType, FocusType] = Foci[FocusType] ?=> ResultType inline def focus[FocusType, ResultType](using inline track: Foci[FocusType]) - (transform: (prior: Optional[FocusType]) ?=> FocusType) - (block: => ResultType) + (transform: (prior: Optional[FocusType]) ?=> FocusType) + (block: => ResultType) : ResultType = val length = track.length block.also: @@ -158,29 +157,29 @@ extension [ResultType, LambdaType[_]](inline mend: Mend[ResultType, LambdaType]) ${Contingency.mendWithin[LambdaType, ResultType2]('mend, 'lambda)} transparent inline def track[FocusType](using DummyImplicit)[AccrualType <: Exception, ResultType] - (accrual: AccrualType) - (inline block: (focus: Optional[FocusType], accrual: AccrualType) ?=> - PartialFunction[Exception, AccrualType]) + (accrual: AccrualType) + (inline block: (focus: Optional[FocusType], + accrual: AccrualType) ?=> PartialFunction[Exception, AccrualType]) : Any = ${Contingency.track[AccrualType, FocusType]('accrual, 'block)} transparent inline def accrue[AccrualType <: Exception](accrual: AccrualType)[ResultType] - (inline block: (accrual: AccrualType) ?=> PartialFunction[Exception, AccrualType]) + (inline block: (accrual: AccrualType) ?=> PartialFunction[Exception, AccrualType]) : Any = ${Contingency.accrue[AccrualType]('accrual, 'block)} extension [AccrualType <: Exception, LambdaType[_]] - (inline accrue: Accrue[AccrualType, LambdaType]) + (inline accrue: Accrue[AccrualType, LambdaType]) inline def within[ResultType](inline lambda: LambdaType[ResultType]) - (using tactic: Tactic[AccrualType], diagnostics: Diagnostics) + (using tactic: Tactic[AccrualType], diagnostics: Diagnostics) : ResultType = ${Contingency.accrueWithin[AccrualType, LambdaType, ResultType]('accrue, 'lambda, 'tactic, 'diagnostics)} extension [AccrualType <: Exception, LambdaType[_], FocusType] - (inline track: Track[AccrualType, LambdaType, FocusType]) + (inline track: Track[AccrualType, LambdaType, FocusType]) inline def within[ResultType](inline lambda: Foci[FocusType] ?=> LambdaType[ResultType]) - (using tactic: Tactic[AccrualType], diagnostics: Diagnostics) + (using tactic: Tactic[AccrualType], diagnostics: Diagnostics) : ResultType = ${Contingency.trackWithin[AccrualType, LambdaType, ResultType, FocusType]('track, 'lambda, 'tactic, 'diagnostics)} diff --git a/src/core/contingency.Accrue.scala b/src/core/contingency.Accrue.scala index e784164..99ffc8b 100644 --- a/src/core/contingency.Accrue.scala +++ b/src/core/contingency.Accrue.scala @@ -17,5 +17,5 @@ package contingency class Accrue[AccrualType <: Exception, LambdaType[_]] - (val initial: AccrualType, - val lambda: (accrual: AccrualType) ?=> PartialFunction[Exception, AccrualType]) + (val initial: AccrualType, + val lambda: (accrual: AccrualType) ?=> PartialFunction[Exception, AccrualType]) diff --git a/src/core/contingency.AccrueTactic.scala b/src/core/contingency.AccrueTactic.scala index 802f555..03dc26f 100644 --- a/src/core/contingency.AccrueTactic.scala +++ b/src/core/contingency.AccrueTactic.scala @@ -24,12 +24,12 @@ import fulminate.* import rudiments.* class AccrueTactic - [ErrorType <: Exception, AccrualType, ResultType] - (label: boundary.Label[Option[ResultType]], - ref: juca.AtomicReference[AccrualType], - initial: AccrualType) - (lambda: (accrual: AccrualType) ?=> PartialFunction[Exception, AccrualType]) - (using val diagnostics: Diagnostics) + [ErrorType <: Exception, AccrualType, ResultType] + (label: boundary.Label[Option[ResultType]], + ref: juca.AtomicReference[AccrualType], + initial: AccrualType) + (lambda: (accrual: AccrualType) ?=> PartialFunction[Exception, AccrualType]) + (using val diagnostics: Diagnostics) extends Tactic[ErrorType]: def record(error: Diagnostics ?=> ErrorType): Unit = ref.getAndUpdate: accrual => diff --git a/src/core/contingency.AmalgamateTactic.scala b/src/core/contingency.AmalgamateTactic.scala index a47ba82..0319738 100644 --- a/src/core/contingency.AmalgamateTactic.scala +++ b/src/core/contingency.AmalgamateTactic.scala @@ -22,8 +22,8 @@ import fulminate.* import rudiments.* class AmalgamateTactic[ErrorType <: Exception, SuccessType] - (label: boundary.Label[SuccessType | ErrorType]) - (using Diagnostics) + (label: boundary.Label[SuccessType | ErrorType]) + (using Diagnostics) extends Tactic[ErrorType]: type Result = SuccessType | ErrorType type Return = SuccessType | ErrorType diff --git a/src/core/contingency.AttemptTactic.scala b/src/core/contingency.AttemptTactic.scala index 2271cf3..f265309 100644 --- a/src/core/contingency.AttemptTactic.scala +++ b/src/core/contingency.AttemptTactic.scala @@ -22,8 +22,8 @@ import fulminate.* import rudiments.* class AttemptTactic[ErrorType <: Exception, SuccessType] - (label: boundary.Label[Attempt[SuccessType, ErrorType]]) - (using Diagnostics) + (label: boundary.Label[Attempt[SuccessType, ErrorType]]) + (using Diagnostics) extends Tactic[ErrorType]: type Result = Attempt[SuccessType, ErrorType] type Return = Attempt[SuccessType, ErrorType] diff --git a/src/core/contingency.Contingency.scala b/src/core/contingency.Contingency.scala index b26b290..024caf6 100644 --- a/src/core/contingency.Contingency.scala +++ b/src/core/contingency.Contingency.scala @@ -49,7 +49,7 @@ object Contingency: abandon(m"unexpected AST: ${other.toString}") private def mapping[ErrorType <: Exception: Type](using Quotes) - (handler: quotes.reflect.Term) + (handler: quotes.reflect.Term) : Map[quotes.reflect.Symbol, quotes.reflect.Symbol] = import quotes.reflect.* @@ -107,7 +107,7 @@ object Contingency: def tend[ErrorTypes <: Exception: Type](handler: Expr[PartialFunction[Exception, ErrorTypes]]) - (using Quotes) + (using Quotes) : Expr[Any] = import quotes.reflect.* @@ -126,10 +126,9 @@ object Contingency: case '[type typeLambda[_]; typeLambda] => '{Tend[typeLambda]($handler)} def track[AccrualType <: Exception: Type, FocusType: Type] - (accrual: Expr[AccrualType], - handler: Expr[(Optional[FocusType], AccrualType) ?=> - PartialFunction[Exception, AccrualType]]) - (using Quotes) + (accrual: Expr[AccrualType], + handler: Expr[(Optional[FocusType], AccrualType) ?=> PartialFunction[Exception, AccrualType]]) + (using Quotes) : Expr[Any] = import quotes.reflect.* @@ -150,9 +149,9 @@ object Contingency: focus, accrual))} def accrue[AccrualType <: Exception: Type] - (accrual: Expr[AccrualType], - handler: Expr[AccrualType ?=> PartialFunction[Exception, AccrualType]]) - (using Quotes) + (accrual: Expr[AccrualType], + handler: Expr[AccrualType ?=> PartialFunction[Exception, AccrualType]]) + (using Quotes) : Expr[Any] = import quotes.reflect.* @@ -215,8 +214,8 @@ object Contingency: lambda.asTerm.select(method).appliedToArgs(tactics.to(List)).asExprOf[ResultType] def mendWithin[ContextType[_]: Type, ResultType: Type] - (mend: Expr[Mend[?, ContextType]], lambda: Expr[ContextType[ResultType]]) - (using Quotes) + (mend: Expr[Mend[?, ContextType]], lambda: Expr[ContextType[ResultType]]) + (using Quotes) : Expr[ResultType] = type ContextResult = ContextType[ResultType] @@ -246,11 +245,11 @@ object Contingency: } def accrueWithin[AccrualType <: Exception: Type, ContextType[_]: Type, ResultType: Type] - (accrue: Expr[Accrue[AccrualType, ContextType]], - lambda: Expr[ContextType[ResultType]], - tactic: Expr[Tactic[AccrualType]], - diagnostics: Expr[Diagnostics]) - (using Quotes) + (accrue: Expr[Accrue[AccrualType, ContextType]], + lambda: Expr[ContextType[ResultType]], + tactic: Expr[Tactic[AccrualType]], + diagnostics: Expr[Diagnostics]) + (using Quotes) : Expr[ResultType] = '{ val ref: juca.AtomicReference[AccrualType] = juca.AtomicReference(null) @@ -285,12 +284,12 @@ object Contingency: } def trackWithin - [AccrualType <: Exception: Type, ContextType[_]: Type, ResultType: Type, FocusType: Type] - (track: Expr[Track[AccrualType, ContextType, FocusType]], - lambda: Expr[Foci[FocusType] ?=> ContextType[ResultType]], - tactic: Expr[Tactic[AccrualType]], - diagnostics: Expr[Diagnostics]) - (using Quotes) + [AccrualType <: Exception: Type, ContextType[_]: Type, ResultType: Type, FocusType: Type] + (track: Expr[Track[AccrualType, ContextType, FocusType]], + lambda: Expr[Foci[FocusType] ?=> ContextType[ResultType]], + tactic: Expr[Tactic[AccrualType]], + diagnostics: Expr[Diagnostics]) + (using Quotes) : Expr[ResultType] = '{ val foci: Foci[FocusType] = TrackFoci() diff --git a/src/core/contingency.EitherTactic.scala b/src/core/contingency.EitherTactic.scala index 9a374df..45f4af6 100644 --- a/src/core/contingency.EitherTactic.scala +++ b/src/core/contingency.EitherTactic.scala @@ -22,8 +22,8 @@ import fulminate.* import rudiments.* class EitherTactic[ErrorType <: Exception, SuccessType] - (label: boundary.Label[Either[ErrorType, SuccessType]]) - (using Diagnostics) + (label: boundary.Label[Either[ErrorType, SuccessType]]) + (using Diagnostics) extends Tactic[ErrorType]: def diagnostics: Diagnostics = summon[Diagnostics] def record(error: Diagnostics ?=> ErrorType): Unit = boundary.break(Left(error))(using label) diff --git a/src/core/contingency.Foci.scala b/src/core/contingency.Foci.scala index d3424c4..1aaa687 100644 --- a/src/core/contingency.Foci.scala +++ b/src/core/contingency.Foci.scala @@ -28,7 +28,7 @@ object Foci: def register(error: Exception): Unit = () def fold[AccrualType](initial: AccrualType) - (lambda: (Optional[FocusType], AccrualType) => PartialFunction[Exception, AccrualType]) + (lambda: (Optional[FocusType], AccrualType) => PartialFunction[Exception, AccrualType]) : AccrualType = initial @@ -40,7 +40,7 @@ trait Foci[FocusType]: def register(error: Exception): Unit def fold[AccrualType](initial: AccrualType) - (lambda: (Optional[FocusType], AccrualType) => PartialFunction[Exception, AccrualType]) + (lambda: (Optional[FocusType], AccrualType) => PartialFunction[Exception, AccrualType]) : AccrualType def supplement(count: Int, transform: Optional[FocusType] => FocusType): Unit @@ -57,7 +57,7 @@ class TrackFoci[FocusType]() extends Foci[FocusType]: focuses.append(Unset) def fold[AccrualType](initial: AccrualType) - (lambda: (Optional[FocusType], AccrualType) => PartialFunction[Exception, AccrualType]) + (lambda: (Optional[FocusType], AccrualType) => PartialFunction[Exception, AccrualType]) : AccrualType = (0 until errors.length).foldLeft(initial): (accrual, index) => lambda(focuses(index), accrual)(errors(index)) diff --git a/src/core/contingency.OptionalTactic.scala b/src/core/contingency.OptionalTactic.scala index b8c22a0..752823f 100644 --- a/src/core/contingency.OptionalTactic.scala +++ b/src/core/contingency.OptionalTactic.scala @@ -23,7 +23,7 @@ import vacuous.* import rudiments.* class OptionalTactic[ErrorType <: Exception, SuccessType] - (label: boundary.Label[Optional[SuccessType]]) + (label: boundary.Label[Optional[SuccessType]]) extends Tactic[ErrorType]: type Result = Optional[SuccessType] type Return = Optional[SuccessType] diff --git a/src/core/contingency.ThrowTactic.scala b/src/core/contingency.ThrowTactic.scala index ba32fb7..3ea2a8f 100644 --- a/src/core/contingency.ThrowTactic.scala +++ b/src/core/contingency.ThrowTactic.scala @@ -21,7 +21,7 @@ import language.experimental.pureFunctions import fulminate.* class ThrowTactic[ErrorType <: Exception, SuccessType]() - (using @annotation.constructorOnly error: CanThrow[ErrorType]) + (using @annotation.constructorOnly error: CanThrow[ErrorType]) extends Tactic[ErrorType]: def diagnostics: Diagnostics = Diagnostics.capture diff --git a/src/core/contingency.Track.scala b/src/core/contingency.Track.scala index ac073bc..5213a2a 100644 --- a/src/core/contingency.Track.scala +++ b/src/core/contingency.Track.scala @@ -19,5 +19,5 @@ package contingency import vacuous.* class Track[AccrualType <: Exception, LambdaType[_], FocusType] - (val initial: AccrualType, - val lambda: (Optional[FocusType], AccrualType) ?=> PartialFunction[Exception, AccrualType]) + (val initial: AccrualType, + val lambda: (Optional[FocusType], AccrualType) ?=> PartialFunction[Exception, AccrualType]) diff --git a/src/core/contingency.TrackTactic.scala b/src/core/contingency.TrackTactic.scala index f097256..ef25962 100644 --- a/src/core/contingency.TrackTactic.scala +++ b/src/core/contingency.TrackTactic.scala @@ -22,11 +22,11 @@ import fulminate.* import rudiments.* class TrackTactic - [ErrorType <: Exception, AccrualType, ResultType, SupplementType] - (label: boundary.Label[Option[ResultType]], - initial: AccrualType, - foci: Foci[SupplementType]) - (using Diagnostics) + [ErrorType <: Exception, AccrualType, ResultType, SupplementType] + (label: boundary.Label[Option[ResultType]], + initial: AccrualType, + foci: Foci[SupplementType]) + (using Diagnostics) extends Tactic[ErrorType]: def diagnostics: Diagnostics = summon[Diagnostics] def record(error: Diagnostics ?=> ErrorType): Unit = foci.register(error)