Skip to content

Instantly share code, notes, and snippets.

View neopryn's full-sized avatar

Jess Ahrens neopryn

  • Skedulo
  • London
View GitHub Profile
@neopryn
neopryn / ts-multidu.ts
Created September 22, 2020 00:04
Multi TS Discriminant Union
type PNGExtension = { extensionType: "PNG", pngRelatedConfig: string }
type JPEGExtension = { extensionType: "JPEG", jpegRelatedConfig: string }
type LineArt = { artType: "lineart", polylines: string[] }
type Shapes = { artType: "shapes", shapes: Shape[] }
type Art = LineArt | Shapes
type Extension = PNGExtension | JPEGExtension
type RenderMetadata = Art & Extension
@neopryn
neopryn / tsdu.ts
Created September 22, 2020 00:03
TS Discriminant Union
type Square = { type: "square", edgeLength: number }
type Circle = { type: "circle", radius: number }
// Here's our Discriminant Union
type Shape = Square | Circle
function exhaustiveCheck(x: never): never {
throw new Error("Didn't expect to get here");
}
@neopryn
neopryn / scalapatternmatch.scala
Created September 22, 2020 00:01
Scala Pattern-Match Example
sealed trait Shape
object Shape {
case class Square(edgeLength: Int) extends Shape
case class Circle(radius: Int) extends Shape
}
def getShapeArea(shape: Shape): Double = shape match {
case Square(edge) => scala.math.pow(edge, 2)
case Circle(radius) => scala.math.Pi * radius * radius
}

Keybase proof

I hereby claim:

  • I am neopryn on github.
  • I am neopryn (https://keybase.io/neopryn) on keybase.
  • I have a public key ASB2RR-fzWJ-5UPeSnZm0iQ85QK9-uvLfrRSXompgtthmQo

To claim this, I am signing this object: