Skip to content

Commit

Permalink
Update indentation style
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Nov 11, 2024
1 parent df40541 commit 6505860
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 72 deletions.
47 changes: 23 additions & 24 deletions src/core/contingency-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] =

Expand All @@ -79,23 +79,22 @@ 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 ?=>
import unsafeExceptions.canThrowAny
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)))
Expand All @@ -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]()
Expand All @@ -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:
Expand All @@ -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)}
4 changes: 2 additions & 2 deletions src/core/contingency.Accrue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])
12 changes: 6 additions & 6 deletions src/core/contingency.AccrueTactic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
4 changes: 2 additions & 2 deletions src/core/contingency.AmalgamateTactic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/contingency.AttemptTactic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
43 changes: 21 additions & 22 deletions src/core/contingency.Contingency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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.*
Expand All @@ -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.*
Expand All @@ -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.*
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/core/contingency.EitherTactic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/core/contingency.Foci.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/core/contingency.OptionalTactic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/core/contingency.ThrowTactic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/contingency.Track.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])
10 changes: 5 additions & 5 deletions src/core/contingency.TrackTactic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6505860

Please sign in to comment.