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
package caliban | |
import caliban.GraphQL._ | |
import zio.ZIO | |
import zio.console.putStrLn | |
import zio.zquery._ | |
object Test2 extends zio.App { | |
case class User(firstName: UQuery[String], lastName: UQuery[String], age: UQuery[Int]) |
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
package caliban | |
import caliban.GraphQL._ | |
import zio.console.putStrLn | |
import zio.ZIO | |
import zio.zquery._ | |
object Test extends zio.App { | |
case class User(firstName: UQuery[String], lastName: UQuery[String], age: UQuery[Int]) |
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
import scala.deriving._ | |
import scala.quoted._ | |
import scala.quoted.matching._ | |
import scala.compiletime._ | |
trait Show[T] { | |
def show(x: T): String | |
} | |
object Show { |
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
// Step 1: | |
// Code generation creates helpers from a GraphQL schema | |
// Character.* and Queries.* here are auto-generated | |
// Step 2: | |
// Build your own queries combining those helpers | |
val character = | |
(Character.name ~ | |
Character.nicknames ~ | |
Character.origin).mapN(CharacterView) |
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
import magnolia.{ CaseClass, Magnolia, SealedTrait } | |
import mercator.Monadic | |
import zio.random.Random | |
import zio.test.{ Gen, Sized } | |
object Generators { | |
implicit val genUnit: Typeclass[Unit] = Gen.unit | |
implicit val genBool: Typeclass[Boolean] = Gen.boolean | |
implicit val genString: Typeclass[String] = Gen.small(Gen.stringN(_)(Gen.alphaNumericChar)) |
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
import language.experimental.macros | |
import language.implicitConversions | |
import magnolia._ | |
trait MyTypeclass[T] { | |
def f(t: T): String | |
} | |
object MyTypeclass { | |
type Typeclass[T] = MyTypeclass[T] |
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
def listen(actorSystem: ActorSystem, topic: String): Task[Queue[String]] = | |
for { | |
queue <- Queue.bounded[String](1000) | |
rts <- Task.runtime[Any] | |
_ <- Task(actorSystem.actorOf(Props(new SubscriberActor(topic, rts, queue)))) | |
} yield queue | |
case class MessageEnvelope(msg: String) | |
class SubscriberActor(topic: String, rts: Runtime[Any], queue: Queue[String]) extends Actor { |
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
Stream.fromEffect { | |
IO.effectAsync[Any, Throwable, List[Message]] { cb => | |
client | |
.receiveMessage(ReceiveMessageRequest.builder.queueUrl(queueUrl).maxNumberOfMessages(10).build) | |
.handle[Unit]((result, err) => { | |
err match { | |
case null => cb(IO.succeed(result.messages.asScala.toList)) | |
case ex => cb(IO.fail(ex)) | |
} | |
}) |
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
def sendMsg(actor: ActorRef, msg: String): Task[String] = | |
IO.fromFuture { implicit ctx => | |
(actor ? msg).mapTo[String] | |
} |
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
def send(client: SqsAsyncClient, queueUrl: String, msg: String): Task[Unit] = | |
IO.effectAsync[Any, Throwable, Unit] { cb => | |
client | |
.sendMessage(SendMessageRequest.builder.queueUrl(queueUrl).messageBody(msg).build) | |
.handle[Unit]((_, err) => { | |
err match { | |
case null => cb(IO.unit) | |
case ex => cb(IO.fail(ex)) | |
} | |
}) |