This file contains hidden or 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
class Example3Test extends AnyFlatSpec with Matchers { | |
import Example3._ | |
it should "add 1 point" in { | |
// given | |
val updatedPoints = new AtomicInteger(0) | |
val userId = UUID.randomUUID() | |
val stubDao = newStubDaoConstantPoints(15, updatedPoints) | |
// when |
This file contains hidden or 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
import java.util.UUID | |
import cats._ | |
import cats.implicits._ | |
class Points[F[_]: Monad](dao: Dao[F]) { | |
def increase(userId: UUID): F[Unit] = | |
for { | |
current <- dao.currentPoints(userId) | |
updated = calculatePointsIncrease(current) |
This file contains hidden or 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
trait Dao[F[_]] { | |
def currentPoints(userId: UUID): F[Int] | |
def updatePoints(userId: UUID, value: Int): F[Unit] | |
} | |
import doobie._ | |
import doobie.implicits._ | |
import doobie.postgres.implicits._ | |
object DefaultDao extends Dao[ConnectionIO] { |
This file contains hidden or 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
it should "add 1 point" in { | |
import Example2._ | |
PointsLogic.calculatePointsIncrease(15) shouldBe 16 | |
} | |
it should "add 3 points" in { | |
import Example2._ | |
PointsLogic.calculatePointsIncrease(16) shouldBe 19 | |
} |
This file contains hidden or 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
class Example1Test extends AnyFlatSpec with Matchers with BeforeAndAfterAll { | |
private var postgres: EmbeddedPostgres = _ | |
private var transactor: Transactor[IO] = _ | |
implicit private val ioContextShift: ContextShift[IO] = | |
IO.contextShift(ExecutionContext.global) | |
override protected def beforeAll(): Unit = { | |
super.beforeAll() | |
postgres = EmbeddedPostgres.builder().start() | |
transactor = Transactor.fromDriverManager[IO]( |
This file contains hidden or 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
import java.util.UUID | |
import doobie._ | |
import doobie.implicits._ | |
import doobie.postgres.implicits._ | |
class Points(dao: Dao) { | |
def increase(userId: UUID): ConnectionIO[Unit] = | |
for { | |
current <- dao.currentPoints(userId) |
This file contains hidden or 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
override def openWebsocket[T, WS_RESULT]( | |
request: Request[T, S], | |
handler: WS_HANDLER[WS_RESULT]): F[WebSocketResponse[WS_RESULT]] = { | |
responseMonad.map(responseMonad.handleError(delegate.openWebsocket(request, handler)) { | |
case e: Exception => | |
logger.error(s"Exception when opening websocket: $request", e) | |
responseMonad.error(e) | |
}) { response => | |
logger.debug(s"Websocket open: $request, with response headers: ${response.headers}") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
case class LetterAndCount(letter: String, count: Int) | |
// result: Response[GitHubResult] is what we've read from the API | |
val firstLetterToName = result.items.groupBy(_.name.toUpperCase.charAt(0)) | |
val pairs = firstLetterToName.toList.map { case (letter, projects) => | |
LetterAndCount(letter.toString, projects.size) | |
}.sortBy(_.letter) | |
pairs |
This file contains hidden or 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
package sttp.client.asynchttpclient.monix | |
import monix.eval.Task | |
import sttp.client._ | |
import sttp.client.ws.{WebSocket, WebSocketResponse} | |
import monix.execution.Scheduler.Implicits.global | |
import sttp.model.ws.WebSocketFrame | |
import scala.concurrent.duration._ |