Skip to content

Instantly share code, notes, and snippets.

View jdegoes's full-sized avatar

John A. De Goes jdegoes

View GitHub Profile
@jdegoes
jdegoes / DynamoDB.scala
Created April 24, 2020 16:58
ZIO DynamoDB
package zio.dynamodb
import java.io.IOException
import zio.{ Chunk, Task, ZLayer }
import zio.blocking.Blocking
/*
~~GetItem~~
WriteItem
@jdegoes
jdegoes / http4k.ks
Created April 23, 2020 15:29
Adding multipart responses into http4k
// RFC: https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
interface Response {
fun multipartBoundary(boundary: String): Response
fun multiparts(): List<Response>
//
// The returned Response will use a content type of multipart response with
// a boundary string determined by the implementation.
//
@jdegoes
jdegoes / ZMX.scala
Created April 10, 2020 15:05
ZMX Design Sketch
package zio
import zio.duration.Duration
package object zmx extends MetricsDataModel with MetricsConfigDataModel {
type Diagnostics = Has[Diagnostics.Service]
object Diagnostics {
trait Service {
@jdegoes
jdegoes / ZIO-1.0.0-RC-migration.md
Created March 4, 2020 12:44
Migration notes for ZIO-1.0.0-RC18

ZIO's last release candidate before 1.0 (RC18) has arrived!

The first question every user needs to ask themselves:

  • Should they upgrade now?
  • Should they wait for ZIO 1.0?

We need some adventurous souls to upgrade now, because the feedback so generated will help convince us we're ready to pull the trigger on ZIO 1.0 in a couple weeks time.

On the other hand, upgrading now is going to be more difficult, because not all ZIO libraries have been updated to RC18 (we are early in that process), and there is very poor documentation.

@jdegoes
jdegoes / zio-workshops.md
Last active December 29, 2019 16:33
Possible ZIO Workshops
  • Scheduling & Retrying with ZIO: A 2 hour workshop that shows how to create and use schedules and retry policies with ZIO. Scheduling covers cache use cases, downloading resources, sending emails; retrying covers flaky web APIs, database connections, etc.
  • ZIO CRUD. A 2 hour workshop showing how to build a basic REST API using ZIO + third-party library.
  • Using ZIO with Legacy Code: A 2 hour workshop that shows how to wrap lots of legacy code: sync code, async code, Future code; and demonstrate use of Runtime to unsafeRun at boundary points for roundtrip integration.
  • Crash Course in ZIO: A 2 hour workshop that covers “hello world” and a few other simple examples of writing programs with ZIO, with an emphasis on thinking functionality (values & operators on values) and using ‘for’ comprehensions successfully.
  • Rethinking Error Management: A 2 hour workshop that shows how to effectively use recoverable and non-recoverable errors, as well as lossless errors, to build resilient apps that
package net.degoes.zio
trait Sql {
type ColumnName
type TableName
sealed trait Table[+A]
/**
* (SELECT *, "foo", table.a + table.b AS sum... FROM table WHERE cond) UNION (SELECT ... FROM table)
final case class ZIO[-R, +E, +A](run: R => Either[E, A]) {
final def map[B](f: A => B): ZIO[R, E, B] =
ZIO(r => run(r).map(f))
final def flatMap[R1 <: R, E1 >: E, B](f: A => ZIO[R1, E1, B]): ZIO[R1, E1, B] =
ZIO(r => run(r).flatMap(a => f(a).run(r)))
final def provide(r: R): ZIO[Any, E, A] =
ZIO(_ => run(r))
@jdegoes
jdegoes / zio-sky.scala
Last active May 24, 2021 19:31
ZIO Workshop - Sky
package net.degoes.zio
import zio._
import java.io.IOException
import scala.annotation.tailrec
import scala.concurrent.ExecutionContext
trait Helpers {
implicit class ZIOExtensions[R, E, A](zio: ZIO[R, E, A]) {
val exited: ZIO[R, Nothing, Int] = zio.fold(_ => 1, _ => 0)
@jdegoes
jdegoes / zio-test.scala
Last active January 6, 2023 14:08
Simple example of testing with ZIO environment
object test {
import scalaz.zio._
type UserID = String
case class UserProfile(name: String)
// The database module:
trait Database {
val database: Database.Service
//
// EXERCISE 4
//
// Create a type class to describe `printLine` and `readLine`.
//
trait Console[F[_]] {
def printLine(line: String): F[Unit]
def readLine: F[String]
}