Skip to content

Instantly share code, notes, and snippets.

View joshburgess's full-sized avatar
💭
🤔

Josh Burgess joshburgess

💭
🤔
View GitHub Profile
@joshburgess
joshburgess / bidirectional-structural.ts
Created July 25, 2018 15:29 — forked from gelisam/bidirectional-structural.ts
bidirectional type-checker in TypeScript
// in response to https://twitter.com/arntzenius/status/1022076441603829760
// types A,B ∷= base | A → B
// terms M ∷= E | λx.M
// exprs E ∷= x | E M | (M : A)
type Type = "Base" | {lhs: Type, tag: "->", rhs: Type};
type Var = string;
type Term = Expr | {tag: "Lam", varname: Var, body: Term};
type Expr = Var | {tag: "App", fn: Expr, arg: Term} | {term: Term, tag: ":", tp: Type};
const Day = ({ get, left, right }) => {
const map = f => Day ({
get: f (extract()),
left, right
})
const extend = f =>
Day ({
get: (left, right) => f (Day ({ get, left, right })),
import R from "ramda";
module.exports = R.mapObjIndexed(R.invoker, {
toJS: 0,
toObject: 0,
toArray: 0,
keys: 0,
reverse: 0,
entrySeq: 0,
@joshburgess
joshburgess / README.md
Created August 10, 2018 01:14 — forked from bfncs/README.md
Slaying a UI Antipattern with TypeScript & TsMonad

Technical overview

A basic Option type

// Option.ts

// definition
export class None {
  readonly tag: 'None' = 'None'
@joshburgess
joshburgess / README.md
Created September 10, 2018 21:56 — forked from OliverJAsh/README.md
FP list combinators demo with fp-ts
tsc && node main.js
@joshburgess
joshburgess / algebraic.ts
Created September 11, 2018 18:14 — forked from SimonAlling/algebraic.ts
Algebraic Data Types in TypeScript
// Types:
type Just<T> = { Just: T }
type Nothing = {}
type Maybe<T> = Just<T> | Nothing
type Left<L> = { Left: L }
type Right<R> = { Right: R }
type Either<L, R> = Left<L> | Right<R>
// For convenience:
@joshburgess
joshburgess / UIPattern.re
Created September 11, 2018 23:56 — forked from busypeoples/UIPattern.re
Slaying a UI Anti Pattern in ReasonML
/*
Slaying a UI Anti Pattern in ReasonML
Based on Kris Jenkins original writing.
http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html
*/
type remoteData 'e 'a =
| NotAsked
| Loading
| Failure 'e
| Success 'a;
type Init<T extends any[], TTail extends any[] = TailArray<T>> = CastArray<{
[K in keyof TTail]: T[keyof T & K];
}>
type PotentialArgs<T extends any[], TResult extends any[] = T> = {
"continue": PotentialArgs<Init<T>, TResult | Init<T>>;
"end": TResult;
}[T extends [] ? "end" : "continue"]
type Args<T extends Function> =
@joshburgess
joshburgess / mtl-style.ts
Created October 10, 2018 00:35 — forked from gcanti/mtl-style.ts
MTL-style using fp-ts
import { Monad, Monad1 } from 'fp-ts/lib/Monad'
import { HKT, URIS, Type } from 'fp-ts/lib/HKT'
import { liftA2 } from 'fp-ts/lib/Apply'
import { flatten } from 'fp-ts/lib/Chain'
import { Newtype, iso } from 'newtype-ts'
// Adapted from https://tech.iheart.com/why-fp-its-the-composition-f585d17b01d3
//
// newtypes