Skip to content

Instantly share code, notes, and snippets.

View dgouyette's full-sized avatar
🏠
Working from home

GOUYETTE Damien dgouyette

🏠
Working from home
View GitHub Profile
val t1Int : Option[Int] = Some(5)
val t2Int :Option[Int]= Some(6)
val t1String : Option[String] = Some("5")
val t2String :Option[String]= Some("6")
case class MyTuple2[T](a : Option[T], b : Option[T]){
def mapN(f : (T, T)=> T) :Option[T] = {
trait Functor[Box[_]] {
def map[In, Out](boxA: Box[In])(f: In => Out): Box[Out]
}
object Functor {
implicit val functorOption = new Functor[Option] {
override def map[In, Out](boxA: Option[In])(f: In => Out) = boxA.map(f)
}
implicit val functorList = new Functor[List] {
@dgouyette
dgouyette / PathOrRepath.scala
Last active May 18, 2017 12:37
PathOrRepath
import pivot.Rules
import jto.validation._
Rules.maxLength(2).validate("messageWithoutPath")//Invalid(List((/,List(ValidationError(List(error.maxLength),WrappedArray(2))))))
val nomEmptyWithPAth = Rules.notEmpty.repath(_ => Path \"newPath")
nomEmptyWithPAth.validate("")// Invalid(List((/newPath,List(ValidationError(List(error.required),WrappedArray())))))
import jto.validation._
import jto.validation.From
import jto.validation.xml.Rules._
import scala.xml.Node
val rule: Rule[Node, Option[String]] = From[Node] { __ => (__ \ "MyPath" ).read[Option[String]] }
case class Foo(
import jto.validation._
sealed trait Color
object Color {
case object Red extends Color
case object Orange extends Color
case object Green extends Color
val colorR : Rule[String, Color] = Rule.fromMapping {
case "Red" => Valid(Red)
case "Orange" => Valid(Orange)
case "Green" => Valid(Green)
import jto.validation.{Rule, VA}
import shapeless.Poly1
import shapeless._
import labelled.{FieldType, field}
object validator extends Poly1 {
implicit def list[H <: Validator[Int], T <: HList](implicit witness: Witness.Aux[H]) : Case.Aux[FieldType[H, String]::T, HList] = at(l => validator(l.head) :: HNil )
implicit def kvString[K <: Validator[String]](implicit witness: Witness.Aux[K]): Case.Aux[FieldType[K, String], VA[String]] = at(in => {
import jto.validation.{Rule, VA}
import shapeless.Witness
import shapeless.labelled.{FieldType, field}
import shapeless._
import scala.language.implicitConversions
trait Validator {
def rules: Rule[String, String]
import jto.validation.{Rule, VA}
import shapeless.Witness
import shapeless.labelled.{FieldType, field}
trait Validator {
this: String =>
val rules: Rule[String, String]
def validate: VA[String] = rules.validate(this)
}
package stripes
import cats.free.Free
import cats.~>
import freek._
@dgouyette
dgouyette / 0_reuse_code.js
Created September 14, 2016 09:00
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console