Skip to content

Instantly share code, notes, and snippets.

View arosien's full-sized avatar

Adam Rosien arosien

View GitHub Profile
@arosien
arosien / example-http-caching-validation.uml
Created December 27, 2019 22:24
PlantUML diagram of HTTP caching validation
@startuml
concise "Client" as Client
concise "Server" as Server
concise "Response freshness" as Cache
Server is idle
Client is idle
@Client
0 is send
import cats._
import cats.implicits._
/*
Box a: forall b. (a -> b) -> b
Codensity f a: forall b. (a -> f b) -> f b
Yoneda f a: forall b. (a -> b) -> f b
https://stackoverflow.com/questions/45287954/is-having-a-a-b-b-equivalent-to-having-an-a
*/
import cats._
import cats.data._
import cats.implicits._
object KleisliReader {
val k = Kleisli[Id, Int, String](i => (i + 1).toString)
Contravariant[Reader[?, String]] // not found
Contravariant[Kleisli[Id, ?, String]] // not found
@arosien
arosien / scala-at-the-sea-20180108.md
Last active January 14, 2019 22:52
(enhanced) notes from my Scala By The Sea meetup talk about "Type-level Programming"

Scala at the Sea: 8 Jan 2019

Adam Rosien @arosien Inner Product LLC

Can you read this? How about you over there? :thumbs_up:

Type-level programming

What is type-level programming?

import $ivy.`org.typelevel::cats-core:1.4.0`
import cats._
import cats.data._
import cats.implicits._
// compose "regular" functions:
def a(s: String): Int = s.length
def b(i: Int): Int = i + 1
def c(i: Int): String = i.toString + "!"

Variance: OOP vs. FP

TODO: introduction

Note: the examples below use the following algebraic data type:

sealed trait Shape
case class Circle(radius: Double) extends Shape
case class Rectangle(height: Double, width: Double) extends Shape
@arosien
arosien / essential-scala-six-concepts.scala
Last active March 14, 2018 23:09
Notes and code from "Essential Scala: Six Core Concepts for Learning Scala", Seattle at the Sea 2018-03-18 (https://www.meetup.com/Seattle-Scala-User-Group/events/244100420/) You can get our (free!) "Essential Scala" book at https://underscore.io/books/essential-scala/
/*
* Algebraic Data Types
*/
// A has a B and C
case class A(b: B, c: C)
// A is a B or C
sealed trait A
case class B() extends A
@arosien
arosien / free-monoid.txt
Created September 22, 2017 23:11
free monoid
@gfixler, free monoid is the easiest and helps generalize the whole "free" thing
let's make a monoid that is a monoid for *anything*
but wait, that doesn't sound possible, everything that can be a monoid has its own rule, that's the whole point
but if you wanted to make a monoid for anything, you can just be really lazy, and instead of actually adding things together, you just collect all the things you want to add
"you want to add an A and an A, sure, the answer is: here's your two A's" HA HA HA free monoids rule
// JsonFormat is from spray-json, reproduced here
trait JsonFormat[A] {
def write(a: A): JsValue
def read(js: JsValue): A
}
implicit class FormatInvariantFunctor[A](format: JsonFormat[A]) {
def xmap[B](f: A => B, g: B => A): JsonFormat[B] =
new JsonFormat[B] {
def write(b: B): JsValue = format.write(g(b))
@arosien
arosien / bloom.scala
Created April 2, 2015 19:24
WIP Bloom collections via Spire Lattices
package net.rosien.lattice
import scalaz._
import scalaz.syntax.order._
/* http://db.cs.berkeley.edu/papers/UCB-lattice-tr.pdf */
sealed trait LValue[A] {
def value: A
}