Skip to content

Instantly share code, notes, and snippets.

John A. De Goes jdegoes

Block or report user

Report or block jdegoes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jdegoes
jdegoes / zio-workshops.md
Last active Dec 29, 2019
Possible ZIO Workshops
View zio-workshops.md
  • 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
View gadts-session1.scala
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)
View mini-zio.scala
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 Nov 27, 2019
ZIO Workshop - Sky
View zio-sky.scala
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 Feb 6, 2020
Simple example of testing with ZIO environment
View zio-test.scala
object test {
import scalaz.zio._
type UserID = String
case class UserProfile(name: String)
// The database module:
trait Database {
val database: Database.Service
View Hangman.scala
//
// EXERCISE 4
//
// Create a type class to describe `printLine` and `readLine`.
//
trait Console[F[_]] {
def printLine(line: String): F[Unit]
def readLine: F[String]
}
@jdegoes
jdegoes / fpmax.scala
Created Jul 13, 2018
FP to the Max — Code Examples
View fpmax.scala
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
@jdegoes
jdegoes / afp-examples.scala
Last active Feb 12, 2019
Example code from Applied Functional Programming with Scala
View afp-examples.scala
package lambdaconf.introfp2
// import scalaz._
// import Scalaz._
object functions {
object totality {
///def f[A]: A = null
def g[A]: A = throw new Error
View GameWorld.scala
object game {
case class Lens[S, A](set: A => S => S, get: S => A) { self =>
def >>> [B](that: Lens[A, B]): Lens[S, B] =
Lens[S, B](
set = (b: B) => (s: S) => self.set(that.set(b)(self.get(s)))(s),
get = (s: S) => that.get(self.get(s))
)
}
case class Prism[S, A](set: A => S, get: S => Option[A]) { self =>
@jdegoes
jdegoes / AsyncToIO.scala
Last active Nov 11, 2017
A sketch of an `Async ~> IO`
View AsyncToIO.scala
val AsyncToIO: NaturalTransformation[Async, IO] {
def apply[A](fa: Async[A]): IO[A] = {
for {
ref <- newIORef[Either[Throwable, A]](Left(new Error("No value")))
counter <- IO(new java.util.concurrent.CountDownLatch(1))
_ <- fa.register(v => ref.set(v).flatMap(_ => IO(counter.countDown()))
_ <- IO(counter.await())
v <- ref.get
a <- v match {
case Left(e) => IO.fail(e)
You can’t perform that action at this time.