Skip to content

Instantly share code, notes, and snippets.

View julien-truffaut's full-sized avatar

Julien Truffaut julien-truffaut

View GitHub Profile
@julien-truffaut
julien-truffaut / FooBar.scala
Created October 22, 2016 21:10
SO: How do I pull apart Case Classes filled with Options in Scala
import monocle.macros.GenIso
import scalaz.std.option._
object Test extends App {
case class Bar(blub: Option[String])
case class Foo(bar: Option[Bar])
val bar = GenIso[Foo, Option[Bar]]
val blub = GenIso[Bar, Option[String]]
trait Semigroup[A] {}
trait Monoid[A] extends Semigroup[A] {}
trait Functor[F[_]] {}
trait Applicative[F[_]] extends Functor[F] {}
trait Foo[A] { override def toString: String = "Foo"}
trait Foo2[A] extends Foo[A] { override def toString: String = "Foo2"}
trait Foo3[A] extends Foo2[A] {override def toString: String = "Foo3"}
@julien-truffaut
julien-truffaut / Monocle_1.3.0.md
Last active October 17, 2016 19:36
release notes

1.3.0

17 October 2016

Addition

  • new unsafe module with select #394 (thanks to cesartl)
  • refactor optics laws to use random functions #357
  • add Wrapped typeclass #365 (thanks to puffnfresh)
  • add State syntax for Optional #387 (thanks to cb372)
@julien-truffaut
julien-truffaut / optics.scala
Created July 24, 2016 16:08
Attempt to get single compose method between optics
package vanilla
sealed trait Optic[G[_,_] <: Optic[G, _, _], S, A] {
def compose[F[_, _] <: Optic[F, _, _], B](o: F[A, B])(implicit lub : Lub[G,F]) : lub.T[S, B] =
lub.compose(self, o)
def self: G[S,A]
def desc: List[String]
}
case class Traversal[A,B](desc : List[String]) extends Optic[Traversal,A,B] {
@julien-truffaut
julien-truffaut / ExampleStyle.scala
Last active July 10, 2016 15:54
Scalacss issue
package foobar.style
import scalacss.Defaults._
object ExampleStyle extends StyleSheet.Inline {
import dsl._
val ul = style(
backgroundColor.blue
)
λ> parseString parseSemVer mempty "1.0.0-alpha+001"
Success (SemVer 1 0 0 [NOSS "alpha"] [NOSI 1])
λ> parseString parseSemVer mempty "1.0.0+20130313144700"
Success (SemVer 1 0 0 [] [NOSI 20130313144700])
λ> parseString parseSemVer mempty "1.0.0"
Success (SemVer 1 0 0 [] [])
@julien-truffaut
julien-truffaut / Algebra.scala
Created March 8, 2016 20:50
Algebra encoding
sealed trait Alg1[A]
case class Foo1(s: String) extends Alg1[Int]
case object Bar1 extends Alg1[Boolean]
sealed trait Alg2[A]
case class Foo2[A](s: String, f: String => A) extends Alg2[A]
case class Bar[A](f: Boolean => A) extends Alg2[A]
@julien-truffaut
julien-truffaut / NestedCoproduct.scala
Last active February 8, 2019 12:28
Free Monad with nested Coproduct
package sandbox
import cats.data.Coproduct
import cats.free.{Free, Inject}
sealed trait Alg1[A]
sealed trait Alg2[A]
sealed trait Alg3[A]
class Alg1Ops[F[_]](implicit I: Inject[Alg1, F]){
@julien-truffaut
julien-truffaut / Example.scala
Created February 25, 2016 20:04
Free example scala coding dojo
package freee
import scalaz.\/
import scalaz.concurrent.Task
object Example extends App {
import Interact._
val program: API[Unit] = for {
_ <- tell("Hey")
@julien-truffaut
julien-truffaut / MyShow.scala
Created January 19, 2016 16:44
Typeclass example
package bilberry.snippet
import scalaz.syntax.functor._
trait MyShow[A] {
def show(a: A): String
}
object MyShow {
def apply[A](implicit ev: MyShow[A]): MyShow[A] = ev // summon the implicit using syntax MyShow[X]