Skip to content

Instantly share code, notes, and snippets.

@gigiigig
gigiigig / console.scala
Last active August 29, 2015 14:06
Type class DI
import scala.language.higherKinds
import scala.language.implicitConversions
import scalaz._
import Scalaz._
import shapeless._
object console {
case class ServiceA(name: String)
case class ServiceB(name: String, sa: ServiceA)
@gigiigig
gigiigig / gist:9d5c17ba848414e4804f
Created October 2, 2014 23:19
2 level monad transformer
import scalaz._
import Scalaz._
object console extends App {
type ListTOption[A] = ListT[Option, A]
val v1: Option[List[\/[String, Int]]] = 1.right[String].point[List].point[Option]
val v2: Option[List[\/[String, Int]]] = 2.right[String].point[List].point[Option]
@gigiigig
gigiigig / transformer.scala
Created October 8, 2014 12:22
Transformer
import scala.concurrent.Future
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scalaz._
import Scalaz._
object Console extends App {
val v1: Future[Option[Int]] = 1.point[Option].point[Future]
@gigiigig
gigiigig / validationtransformer.scala
Last active August 29, 2015 14:07
Make EitherT work with Validation
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scalaz._
import Scalaz._
object console extends App {
val v1: Future[Validation[String, Int]] = 1.success[String].point[Future]
val v2: Future[Validation[String, Int]] = 1.success[String].point[Future]
@gigiigig
gigiigig / build.sbt
Created December 1, 2014 18:15
Sbt experiment build
scalaVersion := "2.11.1"
resolvers ++= Seq(
"Sonatype OSS Releases" at "http://oss.sonatype.org/content/repositories/releases/",
"Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/",
"Scalaz Bintray Repo" at "http://dl.bintray.com/scalaz/releases"
)
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.0.0",
@gigiigig
gigiigig / validation.scala
Created February 2, 2015 17:29
Validation example
import scalaz._
import Scalaz._
import shapeless._
import shapeless.record._
import shapeless.ops.record._
import shapeless.syntax.singleton._
object console extends App {
@gigiigig
gigiigig / implicts.scala
Created March 3, 2015 10:45
Implicits Abiguous and Override
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
import scala.concurrent.duration._
import scalaz._
import Scalaz._
object console extends App {
@gigiigig
gigiigig / Dependent Types.scala
Last active August 29, 2015 14:17
Dependent Types experiments
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scalaz._
import Scalaz._
object console extends App {
trait Apart[F]{
type T
type W[X]
@gigiigig
gigiigig / GenericFieldUpdate.scala
Last active August 29, 2015 14:21
Update a field by name for any case class
object console extends App {
import shapeless._
import syntax.singleton._
import record._
case class Foo(s: String, id: Int)
case class Bar(id: Int, b: Boolean)
case class Ciao(d: Double)
@gigiigig
gigiigig / statetrampoline.scala
Created June 24, 2015 14:33
Scalaz StateT Trampolines
package console
import scalaz._, Scalaz._
object console extends App {
def countList[T](l: List[T]): Int = {
val i: State[Int, Int] = init[Int]