-
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.
style: improve formatting with sign indentation
- Loading branch information
Showing
13 changed files
with
62 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
13 changes: 0 additions & 13 deletions
13
analyzer-direct/src/test/scala/io/github/tassiLuca/analyzer/lib/ShowcasingEither.scala
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
dependencies { | ||
implementation(libs.sttp) | ||
implementation(libs.cats.core) | ||
} |
42 changes: 42 additions & 0 deletions
42
commons/src/main/scala/io/github/tassiLuca/dse/examples/boundaries/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,42 @@ | ||
package io.github.tassiLuca.dse.examples.boundaries | ||
|
||
import io.github.tassiLuca.dse.boundaries.either | ||
import io.github.tassiLuca.dse.boundaries.either.? | ||
import sttp.client3.{HttpClientSyncBackend, UriContext, basicRequest} | ||
import sttp.model.Uri | ||
|
||
trait ShowcasingEither: | ||
|
||
def aggregate(xs: List[Uri]): Either[String, List[String]] = either: // boundary | ||
xs.map(doRequest(_).?) // `?` break if doRequest returns a Left | ||
|
||
def monadicAggregate(xs: List[Uri]): Either[String, List[String]] = | ||
xs.foldLeft[Either[String, List[String]]](Right(List.empty)): (acc, uri) => | ||
for | ||
results <- acc | ||
response <- doRequest(uri) | ||
yield results :+ response | ||
|
||
def idiomaticMonadicAggregate(xs: List[Uri]): Either[String, List[String]] = | ||
import cats.implicits.toTraverseOps | ||
// "Given a function which returns a G effect, thread this effect through the running of | ||
// this function on all the values in F, returning an F[B] in a G context." | ||
// | ||
// def traverse[G[_]: Applicative, A, B](fa: F[A])(f: A => G[B]): G[F[B]] | ||
xs.traverse(doRequest) | ||
|
||
def doRequest(endpoint: Uri): Either[String, String] | ||
// a possible implementation: | ||
// HttpClientSyncBackend().send(basicRequest.get(endpoint)).body | ||
|
||
trait TestShowcasingEither extends ShowcasingEither with App: | ||
val uris = List(uri"https://www.google.com", uri"https://www.bing.com") | ||
println(aggregate(uris)) | ||
println(monadicAggregate(uris)) | ||
println(idiomaticMonadicAggregate(uris)) | ||
|
||
object TestRightShowcasingEither extends TestShowcasingEither: | ||
override def doRequest(endpoint: Uri): Either[String, String] = Right("Ok") | ||
|
||
object TestLeftShowcasingEither extends TestShowcasingEither: | ||
override def doRequest(endpoint: Uri): Either[String, String] = Left("Ouch!") |
2 changes: 1 addition & 1 deletion
2
...ssiLuca/dse/effects/EffectsShowcase.scala → ...se/examples/effects/EffectsShowcase.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
4 changes: 2 additions & 2 deletions
4
...hub/tassiLuca/dse/effects/Generator.scala → ...Luca/dse/examples/effects/Generator.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
2 changes: 1 addition & 1 deletion
2
...ssiLuca/dse/effects/SaferExceptions.scala → ...se/examples/effects/SaferExceptions.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
2 changes: 1 addition & 1 deletion
2
...siLuca/dse/examples/ShowcasingFlows.scala → .../dse/examples/gears/ShowcasingFlows.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
2 changes: 1 addition & 1 deletion
2
.../dse/examples/UseChannelMultiplexer.scala → ...xamples/gears/UseChannelMultiplexer.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
2 changes: 1 addition & 1 deletion
2
...Luca/dse/examples/UseSimpleChannels.scala → ...se/examples/gears/UseSimpleChannels.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
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