Skip to content

Instantly share code, notes, and snippets.

View arosien's full-sized avatar

Adam Rosien arosien

View GitHub Profile
@arosien
arosien / withOut.scala
Last active May 21, 2020 18:37
Console.withOut
import cats.effect.IO
import java.io.ByteArrayOutputStream
val out = new ByteArrayOutputStream
val cookies = IO(println("cookies"))
Console.withOut(out) { cookies.unsafeRunSync() }
out.toString // "cookies\n"
@arosien
arosien / 20200519.md
Last active May 20, 2020 18:20
"Functional Programming Demystification" @ Scala at the Sea, 19 May 2020

Functional Programming Demystification

Functional programming is full of Fancy Words™. Let's collect a list of them to demystify together. Adam will facilitate with live-coding, and will also try to make good jokes.

Here's some terms to bootstrap us: effect, free monad, functor, property-based testing, refinement type, stream, etc. >

case class RoseF[V, A](root: V, children: List[A])
object RoseF {
type Fixed[V] = Fix[RoseF[V, ?]]
implicit def traverse[V]: Traverse[RoseF[V, ?]] =
new DefaultTraverse[RoseF[V, ?]] {
def traverse[G[_]: Applicative, A, B](
fa: RoseF[V, A]
)(f: A => G[B]): G[RoseF[V, B]] =
@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