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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / sparkathon-agenda.md
Created September 12, 2017 18:05 — forked from jaceklaskowski/sparkathon-agenda.md
Sparkathon in Warsaw - Development Activities
@ioleo
ioleo / DefinedValuesMapExtension.sc
Last active August 5, 2017 21:42
DefinedValuesMapExtension
object workspace {
implicit class DefinedValuesMapExtension[K >: Null, V](map: Map[K, Option[V]]) {
def toDefinedValuesMap: Map[K, V] = map.collect { case (key, value) if value.isDefined => (key, value.get) }
}
val mapWithOptionalValues: Map[String, Option[Int]] = Map(
"foo" -> Some(20),
"bar" -> None,
object OneWayImplicits extends App {
//outside implicits visible, but T is not visible inside
case class Outwards[T](value: T) extends AnyVal
//outside implicits invisible, T is visible inside
case class Inwards[T](value: T) extends AnyVal
implicit def outwardsFromT[T](implicit t: T): Outwards[T] = Outwards(t)
implicit def tFromInwards[T](implicit inw: Inwards[T]): T = inw.value