-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
372 additions
and
299 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
analyzer-direct/src/test/scala/io/github/tassiLuca/analyzer/lib/ShowcasingEither.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.github.tassiLuca.analyzer.lib | ||
|
||
import io.github.tassiLuca.dse.boundaries.either | ||
import io.github.tassiLuca.dse.boundaries.either.? | ||
import sttp.client3.{HttpClientSyncBackend, Response, basicRequest} | ||
import sttp.model.Uri | ||
|
||
def aggregate(xs: List[Uri]): Either[String, List[String]] = | ||
either: // boundary | ||
xs.map(doRequest(_).?) // `?` break if doRequest returns a Left | ||
|
||
def doRequest(endpoint: Uri): Either[String, String] = | ||
HttpClientSyncBackend().send(basicRequest.get(endpoint)).body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
commons/src/main/scala/io/github/tassiLuca/dse/examples/boundaries/EitherRawExamples.scala
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
commons/src/main/scala/io/github/tassiLuca/dse/examples/boundaries/ShowcasingCanFail.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.github.tassiLuca.dse.examples.boundaries | ||
|
||
import io.github.tassiLuca.dse.boundaries.{CanFail, either} | ||
import io.github.tassiLuca.dse.boundaries.either.fail | ||
|
||
import scala.util.boundary | ||
import scala.util.boundary.{Label, break} | ||
|
||
trait ShowcasingCanFail: | ||
|
||
type User | ||
type UserId | ||
type PaymentMethod | ||
|
||
def userBy(id: UserId): User | ||
def verifyUser(id: User): Boolean | ||
def paymentMethodOf(user: User): Option[PaymentMethod] | ||
def verifyMethod(address: PaymentMethod): Boolean | ||
|
||
def getUser(id: UserId)(using CanFail): User = | ||
val user = userBy(id) | ||
if verifyUser(user) then user else fail("Incorrect user") | ||
// fail is a shorthand for `break(Left("Incorrect user"))` | ||
|
||
def getPayment(user: User)(using CanFail): PaymentMethod = | ||
paymentMethodOf(user) match | ||
case Some(a) if verifyMethod(a) => a | ||
case Some(_) => fail("The payment method is not valid") | ||
case _ => fail("Missing payment method") | ||
|
||
def paymentData(id: UserId) = either: | ||
val user = getUser(id) | ||
val address = getPayment(user) | ||
(user, address) |
Oops, something went wrong.