Skip to content

Instantly share code, notes, and snippets.

View julien-truffaut's full-sized avatar

Julien Truffaut julien-truffaut

View GitHub Profile
λ> 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 / 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
)
@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 / 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)
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 / 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]]
import cats.Monad
import cats.data.EitherT
import cats.implicits._
import cats.mtl.implicits._
import cats.mtl.{ApplicativeAsk, FunctorRaise}
import doobie.free.connection.ConnectionIO
object MtlExample {
case class RequestId(value: String)
@julien-truffaut
julien-truffaut / docker.MD
Last active July 18, 2019 13:36
Docker cheat sheet
docker kill $(docker ps -q)    # stop all containers
docker rm $(docker ps -a -q)   # remove all containers
docker rmi $(docker images -q) # remove all docker images
trait Example {
import cats.implicits._
import cats.~>
type VdomNode
type StateSnapshot[A]
type Lens[S, A]
type Layout1 = VdomNode => VdomNode
type Layout2 = (VdomNode, VdomNode) => VdomNode
@julien-truffaut
julien-truffaut / StateOfMonocle.MD
Last active December 18, 2019 14:06
State of Monocle

Monocle, like many other Scala FP libraries, was inspired by Haskell. In our case, it is the Lens library by Edward Kmett and al.

In Monocle, we experimented with various optics encoding: pair of functions, Van Laarhoven, and profunctor (see LensImpl). The JVM and Haskell runtime are hugely different, and an encoding that works well in Haskell can be inefficient in Scala. For example, Haskell relies on zero cost wrapper (newtype) to effectively select typeclass instances, but we don't have an equivalent in Scala/JVM yet (opaque types may help). You can find some of the benchmarks we made for Lenses in 2015 here.

However, something we didn't do very well was to adapt the API to the specificity of Scala. If you look at Monocle 1.x or 2.x, it has the same interface as Haskell Lens but expressed in a much more clunky wa