This is a port of the RemoteData type from Kris Jenkins article „How Elm Slays a UI Antipattern“ to TypeScript with TsMonad. There have been ports to Flow and JavaScript as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import R from "ramda"; | |
module.exports = R.mapObjIndexed(R.invoker, { | |
toJS: 0, | |
toObject: 0, | |
toArray: 0, | |
keys: 0, | |
reverse: 0, | |
entrySeq: 0, |
tsc && node main.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |