@constantiner/fun-ctional
Version:
The library brings most of the familiar functional techniques (like functional composition) to asynchronous world with shining Promises
3 lines (2 loc) • 7.36 kB
JavaScript
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((r=r||self).funCtional={})}(this,function(r){"use strict";function n(r,e){return r[t]=e,r}function u(r){return r[t]}var t=Symbol.for("Custom Promise Handling Support");function i(r,e,t,n,u,a,o){try{var c=r[a](o),i=c.value}catch(r){return void t(r)}c.done?e(i):Promise.resolve(i).then(n,u)}function s(c){return function(){var r=this,o=arguments;return new Promise(function(e,t){var n=c.apply(r,o);function u(r){i(n,e,t,u,a,"next",r)}function a(r){i(n,e,t,u,a,"throw",r)}u(void 0)})}}function a(r){return function(r){if(Array.isArray(r)){for(var e=0,t=new Array(r.length);e<r.length;e++)t[e]=r[e];return t}}(r)||function(r){if(Symbol.iterator in Object(r)||"[object Arguments]"===Object.prototype.toString.call(r))return Array.from(r)}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function o(r){return r?1===r.length&&function(r){return Array.isArray(r)||(r||""===r)&&"function"==typeof r[Symbol.iterator]}(r[0])?a(r[0]):r:[]}function c(a){return function(){var n=s(regeneratorRuntime.mark(function r(e,t,n){var u;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,a(e,t,n);case 2:return u=!!r.sent,r.abrupt("return",{filterResult:u,element:e});case 4:case"end":return r.stop()}},r)}));return function(r,e,t){return n.apply(this,arguments)}}()}function f(r,e){var t=e.filterResult,n=e.element;return t&&r.push(n),r}function e(){var a=0<arguments.length&&void 0!==arguments[0]&&arguments[0];return function(u){return function(){var e=s(regeneratorRuntime.mark(function r(e){var t,n;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,m(e);case 2:return t=r.sent,r.next=5,Promise.all(t);case 5:if(n=r.sent,a)return r.next=9,h(u,n);r.next=12;break;case 9:r.t0=r.sent,r.next=15;break;case 12:return r.next=14,v(u,n);case 14:r.t0=r.sent;case 15:return r.abrupt("return",r.t0);case 16:case"end":return r.stop()}},r)}));return function(r){return e.apply(this,arguments)}}()}}function p(){var c=0<arguments.length&&void 0!==arguments[0]&&arguments[0];return function(o){return function(){var e=s(regeneratorRuntime.mark(function r(n){var u,a;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,m(n);case 2:return u=r.sent,r.next=5,Promise.all(u);case 5:return a=r.sent,r.abrupt("return",c?x(o,a):(e=o,t=a,Promise.all(t.map(e))));case 7:case"end":return r.stop()}var e,t},r)}));return function(r){return e.apply(this,arguments)}}()}}function l(r){var e=function(u){return function(r,e,t,n){return Promise.resolve(r).then(function(r){return u(r,e,t,n)})}}(r[0]),t=a(r);return t[0]=e,t}var m=function(){var e=s(regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.t0=Array,r.next=3,Promise.resolve(e);case 3:return r.t1=r.sent,r.abrupt("return",r.t0.from.call(r.t0,r.t1));case 5:case"end":return r.stop()}},r)}));return function(r){return e.apply(this,arguments)}}(),v=function(){var t=s(regeneratorRuntime.mark(function r(e,t){var n,u;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return n=c(e),r.next=3,Promise.all(t.map(n));case 3:return u=r.sent,r.abrupt("return",u.reduce(f,[]));case 5:case"end":return r.stop()}},r)}));return function(r,e){return t.apply(this,arguments)}}(),h=function(){var t=s(regeneratorRuntime.mark(function r(e,t){var n,u;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:n=[],u=0;case 2:if(u<t.length)return r.next=5,e(t[u],u,t);r.next=10;break;case 5:!!r.sent&&n.push(t[u]);case 7:u++,r.next=2;break;case 10:return r.abrupt("return",n);case 11:case"end":return r.stop()}},r)}));return function(r,e){return t.apply(this,arguments)}}(),y=e(),g=e(!0),x=function(){var t=s(regeneratorRuntime.mark(function r(e,t){var n,u,a;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:n=[],u=0;case 2:if(u<t.length)return r.next=5,e(t[u],u,t);r.next=10;break;case 5:a=r.sent,n.push(a);case 7:u++,r.next=2;break;case 10:return r.abrupt("return",n);case 11:case"end":return r.stop()}},r)}));return function(r,e){return t.apply(this,arguments)}}(),d=p(),w=p(!0),R=function(){var e=s(regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.t0=Promise,r.next=3,m(e);case 3:return r.t1=r.sent,r.abrupt("return",r.t0.all.call(r.t0,r.t1));case 5:case"end":return r.stop()}},r)}));return function(r){return e.apply(this,arguments)}}();r.acatch=function(e){return n(function(r){return Promise.resolve(r).catch(e)},function(r){return r.catch(e)})},r.acompose=function(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];return function(){var e=s(regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",o(t).reduceRight(function(r,e){var t=u(e);return t?t(r):r.then(e)},Promise.resolve(e)));case 1:case"end":return r.stop()}},r)}));return function(r){return e.apply(this,arguments)}}()},r.afilter=y,r.afilterSeq=g,r.amap=d,r.amapSeq=w,r.apipe=function(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];return function(){var e=s(regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",o(t).reduce(function(r,e){var t=u(e);return t?t(r):r.then(e)},Promise.resolve(e)));case 1:case"end":return r.stop()}},r)}));return function(r){return e.apply(this,arguments)}}()},r.applyFns=function(){for(var r=arguments.length,n=new Array(r),e=0;e<r;e++)n[e]=arguments[e];return function(){var e=s(regeneratorRuntime.mark(function r(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,Promise.resolve(e);case 2:return t=r.sent,r.abrupt("return",Promise.all(o(n).map(function(r){return r(t)})));case 4:case"end":return r.stop()}},r)}));return function(r){return e.apply(this,arguments)}}()},r.applySafe=function(e,t){return n(function(r){return Promise.resolve(r).then(e).catch(t)},function(r){return r.then(e).catch(t)})},r.areduce=function(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];return function(){var e=s(regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.t0=Array.prototype.reduce,r.next=3,R(e);case 3:return r.t1=r.sent,r.t2=l(t),r.abrupt("return",r.t0.apply.call(r.t0,r.t1,r.t2));case 6:case"end":return r.stop()}},r)}));return function(r){return e.apply(this,arguments)}}()},r.areduceRight=function(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];return function(){var e=s(regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.t0=Array.prototype.reduceRight,r.next=3,R(e);case 3:return r.t1=r.sent,r.t2=l(t),r.abrupt("return",r.t0.apply.call(r.t0,r.t1,r.t2));case 6:case"end":return r.stop()}},r)}));return function(r){return e.apply(this,arguments)}}()},Object.defineProperty(r,"__esModule",{value:!0})});
//# sourceMappingURL=fun-ctional.min.js.map