Skip to content

Instantly share code, notes, and snippets.

View ioleo's full-sized avatar
🌊
Fighting the tide...

ioleo ioleo

🌊
Fighting the tide...
View GitHub Profile
@ioleo
ioleo / sparkathon-agenda.md
Created September 12, 2017 18:05 — forked from jaceklaskowski/sparkathon-agenda.md
Sparkathon in Warsaw - Development Activities
@ioleo
ioleo / GenericTaglessAlgebra.scala
Last active February 12, 2018 20:17
Example of generic tagless algebra with Cats and Freestyle. Additional type args beyond F[_] in algebras are not currently supported. To work around we use path dependent types.
import cats.data.State
import freestyle.tagless._
/* domain objects */
sealed trait Acme
object Acme {
case object AcmeUK extends Acme
case object AcmeUS extends Acme
}
@ioleo
ioleo / SimpleFreestyleFree.scala
Last active January 26, 2018 12:13
Simple freestyle free program example with single instruction
import cats.data.State
import freestyle.free._
/* domain objects */
case class Id(id: String)
case class AcmeItem(id: Id)
/* state */
trait MapState[K, V] {
@ioleo
ioleo / ArbitraryFreestyleFree.scala
Created January 26, 2018 12:13
Arbitrary freestyle free program example with multiple instructions
import cats.data.State
import freestyle.free._
/* domain objects */
case class Id(id: String)
case class AcmeItem(id: Id)
/* state */
trait MapState[K, V] {
@ioleo
ioleo / ArbitraryFreestyleTagless.scala
Created January 26, 2018 12:17
Arbitrary freestyle tagless program example with multiple instructions
import cats.data.State
import freestyle.tagless._
/* domain objects */
case class Id(id: String)
case class AcmeItem(id: Id)
/* state */
trait MapState[K, V] {
type Type = Map[K, V]
@ioleo
ioleo / SimpleFreestyleTagless.scala
Created January 26, 2018 12:19
Simple freestyle tagless program example with single instruction
import cats.data.State
import freestyle.tagless._
/* domain objects */
case class Id(id: String)
case class AcmeItem(id: Id)
/* state */
trait MapState[K, V] {
type Type = Map[K, V]
@ioleo
ioleo / GenericFreeAlgebra.scala
Last active January 23, 2019 08:48
Example of generic free algebra with Cats and Freestyle. Additional type args beyond F[_] in algebras are not currently supported. To work around we use path dependent types.
import cats.data.State
import freestyle.free._
/* domain objects */
sealed trait Acme
object Acme {
case object AcmeUK extends Acme
case object AcmeUS extends Acme
}
@ioleo
ioleo / TaglessModulesExample.scala
Last active January 23, 2019 08:48
Freestyle tagless program example with multiple algebras composed into module
import cats.Monad
import cats.effect.IO
import freestyle.tagless._
@tagless trait Logger {
def debug(message: String): FS[Unit]
}
@tagless trait Summer {
def sum(a: Int, b: Int): FS[Int]
@ioleo
ioleo / FreeModulesExample.scala
Last active January 23, 2019 08:48
Freestyle free program example with multiple algebras composed into module
import cats.effect.IO
import freestyle.free._
import freestyle.free.implicits._
@free trait Logger {
def debug(message: String): FS[Unit]
}
@free trait Summer {
def sum(a: Int, b: Int): FS[Int]
@ioleo
ioleo / ConfigReader.scala
Created January 29, 2018 20:08
Classy typesafe config reader utils
import classy.{DecodeError, Read}
import classy.config.ConfigDecoder
import com.typesafe.config.Config
import scala.util.{Failure, Success, Try}
object ConfigReader {
def apply[A](f: String => A): Read[Config, A] = { path =>
ConfigDecoder.instance[A] { config =>
Try(f(config.getString(path))) match {