Skip to content

Instantly share code, notes, and snippets.

@indongyoo
Created April 3, 2018 11:59
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 indongyoo/9a22de092433578f3aae2e7f585a8dcd to your computer and use it in GitHub Desktop.
Save indongyoo/9a22de092433578f3aae2e7f585a8dcd to your computer and use it in GitHub Desktop.
const map = curry2((f, coll) =>
coll instanceof Function ?
(..._) => f(coll(..._))
:
coll instanceof Promise ?
coll.then(f)
:
coll instanceof Map ?
reduce((m, [k, v]) => then(val => m.set(k, val), f(v)), new Map, coll.entries())
:
hasIter(coll) ?
reduce((arr, v) => then(v=> (arr.push(v), arr), f(v)), [], coll)
:
isObject(coll) ?
reduce((o, [k, v]) => then(v => (o[k] = v, o), f(v)), {}, ObjIter.entries(coll))
:
[] // else
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment