Skip to content

Instantly share code, notes, and snippets.

View gist:ca4b2d043963ccd1819aa0a87be87f3c
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
View nginx.conf
error_log /usr/local/var/log/nginx/error.log;
worker_processes 4;
#worker_shutdown_timeout 1s;
events {
worker_connections 4096;
}
View play-monix.scala
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)
View tagged.scala
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)
}
View currencygen.scala
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") {
View implicit-conv-tagged.scala
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
View tagged-type.scala
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)
View tagged-type-play-json.scala
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]
View diverging.scala
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)
View ex.scala
sealed trait A
case class B() extends A
case class C() extends A
val xs = List(B(), B(), C())
xs.groupBy(_.getClass)