UNPKG

moy-fp

Version:
23 lines (20 loc) 520 B
import nAry from '../Function/nAry' import map from '../Functor/map' import ap from '../Functor/ap' /** * Functor f => ((a, b, ..., m) -> n) -> ((f a, f b, ..., f m) -> f n) */ const lift = fn => nAry(fn.length, (arg, ...args) => { switch(Object.prototype.toString.call(arg)){ case '[object Array]': case '[object Identity]': case '[object Maybe]': case '[object IO]': case '[object Task]': return args.reduce( ap, map(fn, arg), ) default: return } }) export default lift