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 / build.sbt
Last active September 9, 2015 11:53
gatling custom test config
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"io.gatling.highcharts" % "gatling-charts-highcharts" % "2.1.7" % "test",
"io.gatling" % "gatling-test-framework" % "2.1.7" % "test"
)
lazy val LoadTest = config("load") extend Test
lazy val LoadTest = config("load") extend Test
@julien-truffaut
julien-truffaut / Van_Laarhoven_Lens.md
Last active October 11, 2015 21:15
Abstract for Scala Matsuri 2016

Van Laarhoven Lens

A Lens is a functional concept that permits to zoom in a data structure. A key point of Lenses is that they compose together such as you can drill deeper and deeper in your data. Once you arrive at the level you are interested in, you can either extract or modify (even effectfully!) the value you targeted.

In this presentation, I would like to go through a specific Lens implementation known as Van Laarhoven Lenses. This implementation is particularly interesting because it defines Lenses as a unique function! The game is to find out how can we derive all Lens methods from this simple function.

import monocle.MonocleSuite
import monocle.generic.internal.TupleGeneric
class ProductExample extends MonocleSuite {
case class Example(i : Int, s: String, b: Boolean)
implicit val gen = TupleGeneric[Example]
test("productToTuple creates an Iso between a Product and a Tuple") {
import remotely.{Type, Field, Protocol}
import remotely.codecs._
import remotely._
import remotely.transport.netty.NettyTransport
object protocol {
val definition = Protocol.empty
.codec[Int]
.specify1("factorial", Field.strict[Int]("in"), Type[Int])
}
@julien-truffaut
julien-truffaut / Monocle 1.2.0-M2.md
Last active November 22, 2015 20:42
WIP - Release note for Monocle 1.2.0-M2

1.2.0-M2

Thanks to all the 14 contributors since 1.2.0-M1

Addition

  • add only Prism to match a single value see
  • add below Prism to lift a Prism in a Traverse see
  • add length for Fold and Traversal #236 (thanks to aoiroaoino)
  • add optics for scalaz.Either3 #242 (thanks to aoiroaoino)
import io.circe.Json
import io.circe.optics.all._
import io.circe.parse.parse
import monocle.Iso
import monocle.function.Plated
import monocle.function.all._
object PlatedExample extends App {
val json =
"""{
@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]
@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 / 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 / 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]