Skip to content

Instantly share code, notes, and snippets.

@shutej
Created August 4, 2015 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shutej/a9aa1dcceaca20b4e073 to your computer and use it in GitHub Desktop.
Save shutej/a9aa1dcceaca20b4e073 to your computer and use it in GitHub Desktop.
/* @flow */
function identity<T>(x: T): T {
return x;
}
function fmapArray<T, U>(fn: (t: T) => U): (a: ?Array<T>) => Array<U> {
return function(x) {
if (!x) {
return [];
}
return x.map(fn);
};
}
function fmapMap<T, U>(fn: (t: T) => U): (m: ?Map<string, T>) => { [k: string]: U } {
return function(x) {
var retval = {};
if (!x) {
return retval;
}
for (var y of x) {
retval[y[0]] = fn(y[1]);
}
return retval;
};
}
export type T = { x: string; };
export function empty(): T { return { x: "" }; }
export function marshal<U>(x: T): U { return (function(x) { return { X: identity(x.x) }; })(x); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment