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
5.3.1 Co-Kleisli morphisms | |
Definition 5.3.5. Let (C, ε, ν) be a comonad on C. A co-Kleisli morphism of C from X to Y is a | |
morphism CX → Y of C. | |
Here is a typical situation in science. Suppose that, during an experiment, we have a process | |
f taking an input x ∈ X and giving an output y ∈ Y. This could be for example a survey in | |
which we ask people of different age (X) what their political views are (Y). Suppose that we | |
repeat the experiment, feeding again the same input x to f . It could happen that this time we | |
get a different outcome than before, y | |
′ , y. For example, suppose a person of age x expresses | |
political view y. Another person of the same age x may express a different political view y |
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
error_log /usr/local/var/log/nginx/error.log; | |
worker_processes 4; | |
#worker_shutdown_timeout 1s; | |
events { | |
worker_connections 4096; | |
} |
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 ActionBuilder2[+R[_]] extends ActionBuilder[R] { self => | |
def async2(block: => Task[Result]): Action[AnyContent] = | |
async(block runAsync) | |
def async2(block: R[AnyContent] => Task[Result]): Action[AnyContent] = | |
async(block(_) runAsync) | |
def async2[A](bodyParser: BodyParser[A])(block: R[A] => Task[Result]): Action[A] = | |
async(bodyParser)(block(_) runAsync) |
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
implicit def taggedStringFormat[T]: Format[String @@ T] = new Format[String @@ T] { | |
def reads(json: JsValue): JsResult[String @@ T] = json match { | |
case JsString(v) => JsSuccess(tag[T](v)) | |
case unknown => JsError(s"String value expected, got: $unknown") | |
} | |
def writes(v: String @@ T): JsValue = JsString(v) | |
} |
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 models | |
import org.scalacheck.Arbitrary._ | |
import org.scalacheck.Shapeless._ | |
import org.scalacheck._ | |
import shapeless.tag | |
import shapeless.tag.{apply => _, _} | |
object ArbitraryModelsSpecification extends Properties("ArbitraryModelsSpecification") { |
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 shapeless.tag | |
import shapeless.tag._ | |
implicit def toTaggedType[U, T](u: U): U @@ T = tag[T](u) | |
//implicit def toTaggedString[T](s: String): String @@ T = tag[T](s) | |
trait MyTag | |
def foo(s: String @@ MyTag): String @@ MyTag = 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
import shapeless.tag.@@ | |
import org.scalacheck.Prop.forAll | |
import org.scalacheck.Shapeless._ | |
trait Baz | |
case class Foo(s: String @@ Baz) | |
case class Bar(f: 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 play.api.libs.json.{Format, JsResult, JsValue, Json} | |
import shapeless.tag.@@ | |
trait Money | |
case class Amount(price: String @@ Money) | |
private val amountWrites = Json.writes[Amount] | |
private val amountReads = Json.reads[Amount] |
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 org.scalacheck.Arbitrary | |
import org.scalacheck.Arbitrary._ | |
import org.scalacheck.Gen | |
def arbitraryCaseClass[A,C](f: A => C)(implicit t: Arbitrary[A]): Arbitrary[C] = Arbitrary(for(v <- arbitrary[A]) yield f(v)) | |
type MyIdType = String | |
implicit val arbMyIdType: Arbitrary[MyIdType] = Arbitrary(Gen.identifier) |
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
sealed trait A | |
case class B() extends A | |
case class C() extends A | |
val xs = List(B(), B(), C()) | |
xs.groupBy(_.getClass) |
NewerOlder