Skip to content

Commit febe88e

Browse files
committed
Revert "steps evalutator trait"
This reverts commit 7768f0a.
1 parent 7768f0a commit febe88e

File tree

2 files changed

+8
-56
lines changed

2 files changed

+8
-56
lines changed

src/main/scala/steps/result/package.scala

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import scala.util.boundary
1010
import scala.annotation.implicitNotFound
1111
import scala.Conversion.into
1212
import scala.util.boundary.Label
13-
import steps.result.Result.eval.break
1413

1514
/** Represents either a success value of type `T` or an error of type `E`. It
1615
* can be used when expecting results that have errors that should be inspected
@@ -458,51 +457,6 @@ object Result:
458457

459458
// Boundary and break
460459

461-
trait Evaluator[Impl[+_,+_]]:
462-
self =>
463-
type Success[+T]
464-
type Failure[+E]
465-
466-
inline def foldValue[T, E](impl: Impl[T, E])[U](inline onSuccess: T => U, inline onFailure: Failure[E] => U): U
467-
inline def failure[E](error: E): Failure[E]
468-
469-
extension [T, E](
470-
using @implicitNotFound(
471-
"`break` cannot be used outside of the `Result.apply` scope."
472-
)
473-
label: boundary.Label[Failure[E]])(impl: into[Impl[T, E]]) {
474-
final inline def ok: T = foldValue(impl)(t => t, boundary.break(_))
475-
}
476-
477-
trait EvaluatorCompanion[Impl[+_,+_]]:
478-
479-
final inline def raise[E](using eval: Evaluator[Impl])(using
480-
@implicitNotFound(
481-
"`raise` cannot be used outside of the `Result.apply` scope."
482-
)
483-
label: boundary.Label[eval.Failure[E]]
484-
)(inline err: into[E]): Nothing = boundary.break(eval.failure(err))
485-
486-
final inline def break[T, E](using eval: Evaluator[Impl])(using
487-
@implicitNotFound(
488-
"`break` cannot be used outside of the `Result.apply` scope."
489-
)
490-
label: boundary.Label[Impl[T, E]]
491-
)(inline res: into[Impl[T, E]]): Nothing = boundary.break(res)
492-
493-
given resultEvaluator: Evaluator[Result] with
494-
type Success[T] = Ok[T]
495-
type Failure[E] = Err[E]
496-
497-
inline def foldValue[T, E](impl: Result[T, E])[U](inline onSuccess: T => U, inline onFailure: Err[E] => U): U =
498-
impl match
499-
case Ok(value) => onSuccess(value)
500-
case err: Err[E] => onFailure(err)
501-
502-
inline def failure[E](error: E): Err[E] = Err(error)
503-
504-
object eval2 extends EvaluatorCompanion[Result]
505-
506460
// Currently under its own object `eval` due to https://github.com/scala/scala3/issues/20126
507461

508462
/** Evaluates `body`, returning the output as an [[Ok]] value.

src/test/scala/steps/result/Result.scala

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import scala.util.Try
33
import language.experimental.captureChecking
44

55
import steps.result.Result
6-
import steps.result.Result.{eval as _, *}
7-
// import steps.result.Result.eval.*
8-
9-
import steps.result.Result.eval2.*
6+
import steps.result.Result.*
7+
import steps.result.Result.eval.*
108

119
class ResultTest extends munit.FunSuite {
1210

@@ -167,12 +165,12 @@ class ResultTest extends munit.FunSuite {
167165

168166
def log2(input: Int): Result[Int, LogErr] =
169167
Result:
170-
if input < 1 then eval2.raise(NoLog)
168+
if input < 1 then eval.raise(NoLog)
171169
else if input == 1 then 0
172170
else log2(input / 2).ok + 1
173171

174172
Result[Int, Exception]: label ?=>
175-
Result.resultEvaluator.ok(log2(5))//.ok
173+
log2(5).ok
176174

177175
assertEquals(log2(4), Ok(2))
178176
assertEquals(log2(-1), Err(LogErr.NL(NoLog)))
@@ -210,15 +208,15 @@ class ResultTest extends munit.FunSuite {
210208
case Seq() => init
211209
case Seq(h, t*) =>
212210
val next = f(init, h).ok
213-
eval2.break(tryFoldLeft(next, f)(t))
211+
eval.break(tryFoldLeft(next, f)(t))
214212
}
215213

216214
test("implicit upcasting") {
217215
import steps.result.Conversions.Lift.given
218216

219217
Result[Int, Nothing]:
220218
val t: Result[Int, String] = 1
221-
eval2.break(1)
219+
eval.break(1)
222220
}
223221

224222
test("iterable") {
@@ -251,7 +249,7 @@ class ResultTest extends munit.FunSuite {
251249
Result[Int, Bar]: l1 ?=>
252250
Result[String, Foo]: l2 ?=>
253251
val r: Result[String, Int] = Result.Err(1)
254-
val str: String = eval2.ok(using l1)(r)
252+
val str: String = eval.ok(using l1)(r)
255253
str
256254
.ok.length
257255
}
@@ -261,7 +259,7 @@ class ResultTest extends munit.FunSuite {
261259
test("break error") {
262260
given Conversion[String, Int] = _.length // comment for failure
263261
Result[Int, Int]:
264-
val z = eval2.break(err)
262+
val z = eval.break(err)
265263
1
266264
}
267265

0 commit comments

Comments
 (0)