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
case class Action[S](when: (S) => Boolean, | |
then: (S) => Either[String, S], | |
name: String = "") | |
{ | |
def apply(state: S): Either[String, S] = | |
if (when(state)) then(state) | |
else Left(s"The system could not execute the action '$name'.") | |
} | |
case class Goal[S](actionSet: List[Action[S]], name: 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 scalaz.\/ | |
import scalaz.\/._ | |
import scalaz.syntax.std.boolean._ | |
case class Action[S](when: S => Boolean, then: S => String \/ S, name: String = "") { | |
def apply(state: S): String \/ S = | |
when(state) ? then(state) | left(s"The system could not execute the action '$name'.") | |
} |
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
object Foo { | |
def given[A,B,C,S](aa: S => Stream[A], | |
bb: S => Stream[B], | |
cc: S => Stream[C]) = new { | |
def thereExists(f: (A,B,C)=>Boolean)(s: S): Boolean = { | |
val cross = for { | |
a <- aa(s) | |
b <- bb(s) | |
c <- cc(s) |
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
def forAll[A, B, S](generatorA: (S) => List[A], generatorB: (S) => List[B], predicate: (A, B) => Boolean): (S) => Boolean = { | |
(state) => | |
(for { | |
a <- generatorA(state) | |
b <- generatorB(state) | |
} yield (a, b)).forall(predicate.tupled) | |
} | |
def thereExists[A, B, C, S](generatorA: (S) => List[A], generatorB: (S) => List[B], generatorC: (S) => List[C], predicate: (A, B, C) => Boolean): (S) => Boolean = { | |
(state) => |
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
/* The Scalaz version would look something like this: */ | |
import scalaz.Lens.lensg | |
val bandNameL = lensg[Band, String](b => n => b.copy(name = n), _.name) | |
val guitarTuningL = lensg[Guitar, String](g => t => g.copy(tuning = t), _.tuning) | |
// KeyedLens #1: Here Person is a key. | |
def guitarL(p: Person) = lensg[Band, Guitar]( | |
b => newValue => b.copy(members = b.members + (p -> newValue)), | |
b => b.members(p)) |
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
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/bin/java -Didea.launcher.port=7534 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 13.app/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/javafx-doclet.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/htmlconverter.jar:/Li |
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
object ET { | |
import scalaz.Lens | |
case class Foo[A](a: A, i: Int) | |
object Foo { | |
def a[A]: Lens[Foo[A],A] = Lens.lensg(x => y => x.copy(a=y), _.a) | |
def i1[A]: Lens[Foo[A],Int] = Lens.lensg(x => y => x.copy(i=y), _.i) | |
def i2: Lens[Foo[A] forSome {type A},Int] = Lens.lensg(x => y => x.copy(i=y), _.i) | |
def i3: Lens[Foo[_],Int] = Lens.lensg(x => y => x.copy(i=y), _.i) | |
} |
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 net.arya.util.nice_range | |
/** | |
* Supports ranges and increments of things that aren't numbers. | |
* Example usage at the end. | |
* Created by arya on 8/4/14. | |
*/ | |
/** Syntax for constructing Ranges: start upTo end */ | |
object syntax { |
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
def uptoM(max: Int, a: Parser[A]): Parser[List[A]] = { | |
opt(a).flatMap({ | |
case None => ok(Nil) | |
case Some(r) => ok(r) ~ uptoM(max-1, a) map { case (a,rest) => a :: rest } | |
}) | |
} | |
def manyNM[A](min: Int, max: Int, a: Parser[A]): Parser[List[A]] = | |
manyN(min, a) ~ uptoM(max-min, a) map { case (l,r) => l ++ r } |
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
object Example { | |
import play.api.libs.json._ | |
import play.api.libs.functional.syntax._ | |
import XForms._ | |
// example 1 | |
def namedTupleXforms[F[_]:XForms,A:F,B:F](key1: String, key2: String) = | |
(__ \ key1).xform[F,A] and (__ \ key2).xform[F,B] tupled |
OlderNewer