Skip to content

Commit

Permalink
style: improve formatting with sign indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tassiluca committed Mar 21, 2024
1 parent bfaf45e commit 5ac1d1b
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 39 deletions.
5 changes: 0 additions & 5 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ object Analyzer:
*/
def incremental(service: RepositoryService): Analyzer = IncrementalAnalyzer(service)

/** @return a version of the [[Analyzer]] internally using the new Flow abstraction. */
def flowing(service: RepositoryService): Analyzer = FlowingAnalyzer(service)

This file was deleted.

4 changes: 4 additions & 0 deletions commons/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
implementation(libs.sttp)
implementation(libs.cats.core)
}
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!")
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tassiLuca.dse.effects
package io.github.tassiLuca.dse.examples.effects

import gears.async.AsyncOperations.sleep
import gears.async.default.given
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.tassiLuca.dse.effects
package io.github.tassiLuca.dse.examples.effects

import gears.async.VThreadSupport.{boundary, suspend}
import io.github.tassiLuca.dse.effects.Tree.{Inner, Leaf}
import Tree.{Inner, Leaf}

enum Tree[T]:
case Leaf(x: T)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tassiLuca.dse.effects
package io.github.tassiLuca.dse.examples.effects

import scala.annotation.experimental

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tassiLuca.dse.examples
package io.github.tassiLuca.dse.examples.gears

import gears.async.AsyncOperations.sleep
import gears.async.default.given
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tassiLuca.dse.examples
package io.github.tassiLuca.dse.examples.gears

import gears.async.*
import gears.async.TaskSchedule.Every
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.tassiLuca.dse.examples
package io.github.tassiLuca.dse.examples.gears

import gears.async.*
import gears.async.AsyncOperations.sleep
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.tassiLuca.dse.pimping

import gears.async.Channel.Closed
import gears.async.{Async, BufferedChannel, Channel, SyncChannel, UnboundedChannel}
import gears.async.{Async, BufferedChannel, Channel, UnboundedChannel}

import scala.annotation.tailrec
import scala.language.postfixOps
Expand All @@ -22,7 +22,7 @@ class ChannelTerminatedException extends Exception
* still allowing to consumer to read pending values.
* Trying to `send` values after its termination arise a [[ChannelTerminatedException]].
* When one consumer reads the [[Terminated]] token, the channel is closed. Any subsequent
* read will return `Left(Channel.Closed`.
* read will return `Left(Channel.Closed)`.
*/
trait TerminableChannel[T] extends Channel[Terminable[T]]:
def terminate()(using Async): Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,21 @@ import javax.swing.SwingUtilities
trait SwingDashboardService(view: DashboardUI) extends DashboardServiceComponent:
override val dashboard: DashboardService = new DashboardService:

override def temperatureUpdated(temperature: Temperature): Unit = SwingUtilities.invokeLater { () =>
override def temperatureUpdated(temperature: Temperature): Unit = SwingUtilities.invokeLater: () =>
view.temperatureLabel.setText(s"$temperature °C")
}

override def offHeaterNotified(): Unit = SwingUtilities.invokeLater { () =>
override def offHeaterNotified(): Unit = SwingUtilities.invokeLater: () =>
view.heaterLabel.setText("Off")
}

override def onHeaterNotified(): Unit = SwingUtilities.invokeLater { () =>
override def onHeaterNotified(): Unit = SwingUtilities.invokeLater: () =>
view.heaterLabel.setText("On")
}

override def alertNotified(message: String): Unit = SwingUtilities.invokeLater { () =>
override def alertNotified(message: String): Unit = SwingUtilities.invokeLater: () =>
view.alertsModel.insertRow(0, Array[AnyRef](message))
}

override def luminosityUpdate(luminosity: Luminosity): Unit = SwingUtilities.invokeLater { () =>
override def luminosityUpdate(luminosity: Luminosity): Unit = SwingUtilities.invokeLater: () =>
view.luminosityLabel.setText(s"$luminosity lux")
}

override def updateSchedule(schedule: Map[(String, String), String]): Unit = SwingUtilities.invokeLater { () =>
override def updateSchedule(schedule: Map[(String, String), String]): Unit = SwingUtilities.invokeLater: () =>
view.scheduleModel.setRowCount(0)
schedule.foreach((d, t) => view.scheduleModel.addRow(Array[AnyRef](d._1, d._2, t)))
}

0 comments on commit 5ac1d1b

Please sign in to comment.