17 October 2016
λ> 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 [] []) |
package foobar.style | |
import scalacss.Defaults._ | |
object ExampleStyle extends StyleSheet.Inline { | |
import dsl._ | |
val ul = style( | |
backgroundColor.blue | |
) |
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] { |
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"} |
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) |
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 |
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