Skip to content

Instantly share code, notes, and snippets.

@AndreasKostler
AndreasKostler / unboxed.scala
Last active June 24, 2016 07:00
Unboxed recursive union types via the Curry Howard Correspondence
object UnionTypes {
private type ¬[A] = A => Nothing
private type ¬¬[A] = ¬[¬[A]]
private type ∈[S, T <: Disjunction] = ¬¬[S] <:< ¬[T#D]
private type ∉[S, T <: Disjunction] = ¬¬[S] <:!< ¬[T#D]
/** `S` is `T`. */
type Is[S, T] = ∈[S, OneOf[T]#Or[Nothing]]
@AndreasKostler
AndreasKostler / SellId.scala
Last active April 16, 2019 09:16
Typed routing
package model
import algebra.DeleteDealerErrors.SellIdError
import cats.MonadError
import play.api.libs.json._
import play.api.mvc.PathBindable
import scala.util.Try
final case class SellId(value: String)
@AndreasKostler
AndreasKostler / keybase.md
Last active September 13, 2019 08:19
keybase.md

Keybase proof

I hereby claim:

  • I am andreaskostler on github.
  • I am kandre1980 (https://keybase.io/kandre1980) on keybase.
  • I have a public key ASAXdg4Wt3DUsCSjWq9LXIf6oCNka0lb1LbHvzYhbEyKMAo

To claim this, I am signing this object:

@AndreasKostler
AndreasKostler / flatten.scala
Created November 26, 2019 21:21
Theorem flatten
// Super simple, recursive flatten
// The _ means we have a weakly polymorphic type
// i.e. we don't care about what type _ is (it will, or will not, be resolved later)
// the type signature for flatMap on Seq is Seq[A] => (A => Seq[B]) => Seq[B]
def flatten(s: Seq[_]): Seq[_] = s flatMap {
case s: Seq[_] => flatten(s) // If s is a Seq, we recursively flatten
case s => Seq(s) // If s is atomic, we're done; just package up s
}
// degenerate case