Skip to content

Commit

Permalink
Provide a "dumb Foci" instance
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Sep 15, 2024
1 parent cefcba8 commit 18666cc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/contingency.Contingency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ object Contingency:
(using Quotes)
: Expr[ResultType] =

'{ val foci: Foci[FocusType] = Foci()
'{ val foci: Foci[FocusType] = TraceFoci()
val result = boundary[Option[ResultType]]: label ?=>
${ import quotes.reflect.*

Expand Down
26 changes: 25 additions & 1 deletion src/core/contingency.Foci.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,31 @@ import vacuous.*

import scala.collection.mutable as scm

class Foci[FocusType]():
object Foci:
given [FocusType] => Foci[FocusType] = new:
def length: Int = 0
def success: Boolean = false
def register(error: Exception): Unit = ()

def fold[AccrualType](initial: AccrualType)
(lambda: (Optional[FocusType], AccrualType) => PartialFunction[Exception, AccrualType])
: AccrualType =
initial

def supplement(count: Int, transform: Optional[FocusType] => FocusType): Unit = ()

trait Foci[FocusType]:
def length: Int
def success: Boolean
def register(error: Exception): Unit

def fold[AccrualType](initial: AccrualType)
(lambda: (Optional[FocusType], AccrualType) => PartialFunction[Exception, AccrualType])
: AccrualType

def supplement(count: Int, transform: Optional[FocusType] => FocusType): Unit

class TraceFoci[FocusType]() extends Foci[FocusType]:
private val errors: scm.ArrayBuffer[Exception] = scm.ArrayBuffer()
private val focuses: scm.ArrayBuffer[Optional[FocusType]] = scm.ArrayBuffer()

Expand Down

0 comments on commit 18666cc

Please sign in to comment.