Created
August 4, 2015 15:02
-
-
Save shutej/a9aa1dcceaca20b4e073 to your computer and use it in GitHub Desktop.
This file contains 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
/* @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