This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()))))) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package stripes | |
import cats.free.Free | |
import cats.~> | |
import freek._ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
NewerOlder