Skip to content

Instantly share code, notes, and snippets.

@piq9117
Forked from puffnfresh/LoadedData.ts
Created February 24, 2020 05:23
Show Gist options
  • Save piq9117/720c7f854c3c8dfd8c51b3affd63bd2a to your computer and use it in GitHub Desktop.
Save piq9117/720c7f854c3c8dfd8c51b3affd63bd2a to your computer and use it in GitHub Desktop.
type LoadedData<A> =
<B>(f: (a: A) => B, g: (e: Error) => B, b: B) => B;
function loaded<A>(a: A): LoadedData<A> {
return <B>(f: (a: A) => B, error: (e: Error) => B, empty: B) => f(a);
}
function error<A>(e: Error): LoadedData<A> {
return <B>(success: (a: A) => B, f: (e: Error) => B, empty: B) => f(e);
}
function loading<A>(): LoadedData<A> {
return <B>(success: (a: A) => B, error: (e: Error) => B, e:B ) => e;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment