pepka 0.13.0-b1 → 0.13.0-b10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=function(){},r=r=>{let t=0;for(const s of r)s!==e&&t++;return t},t=(r,t)=>{const s=r.length,o=r.slice(),p=t.length;let n=p,c=0;for(;n&&c<s;c++)o[c]===e&&(o[c]=t[p-n],n--);for(c=s;n;c++,n--)o[c]=t[p-n];return o},s=(e,o,p)=>{const n=e.length-o.length-r(p);if(n<1)return e(...t(o,p));{const r=(...r)=>s(e,t(o,p),r);return r.$args_left=n,r}},o=e=>(...t)=>e.length>r(t)?s(e,[],t):e(...t),p=e=>typeof e,n=e=>null===e,c=e=>"number"==p(e),x=e=>Array.isArray(e),a=e=>"function"===p(e),l={u:"U",b:"B",n:"N",s:"S",f:"F"},i=e=>{const r=p(e);return"object"===r?n(e)?"Null":e.constructor.name:l[r[0]]+r.slice(1)},u=o(((e,r)=>(r.push(e),r))),f=o(((e,r,t)=>(t[e]=r,t))),d=o(((e,r,t)=>t.reduce(e,r))),h=o(((e,r,t)=>{for(let s in t)switch(i(t[s])){case"Array":if(e>1&&"Array"===i(r[s]))switch(e){case 2:const o=r[s],p=t[s];for(const r in p)o[r]?h(e,o[r],p[r]):o[r]=p[r];break;case 3:r[s].push(...t[s])}else r[s]=t[s];break;case"Object":if("Object"===i(r[s])){h(e,r[s],t[s]);break}default:r[s]=t[s]}return r})),m=h(1),g=h(2),y=h(3),b=o(((e,r)=>{let t,s,o,p;for(t in e)s=e[t],[o,p]=a(s)?s(r):[s,r[t]],r[o]=p,t!==o&&delete r[t];return r})),j=o(((e,r)=>{const t=x(r);for(let s in r)e(r[s],s)||(t?r.splice(s,1):delete r[s]);return r})),O=o(((e,r)=>r.indexOf(e))),w=o(((e,r)=>{const t=i(e);if(t===i(r)&&("Object"===t||"Array"==t)){if(n(e)||n(r))return e===r;if(e===r)return!0;for(const t of[e,r])for(const s in t)if(!(t===r&&s in e||t===e&&s in r&&w(e[s],r[s])))return!1;return!0}return e===r})),q=o(((e,r,t,s)=>e(s)?r(s):t(s))),A=o(((e,r,t)=>q(e,r,F,t))),E=(...r)=>(t=e)=>{for(let s=$(r)-1;s>-1;s--)t=t===e?r[s]():r[s](t);return t},k=o(((e,r)=>e.bind(r))),v=o(((e,r)=>r[e])),P=o(((e,r)=>{if((e=>"string"===p(e))(r))return r.includes(e);for(const t of r)if(w(t,e))return!0;return!1})),S=o(((e,r,t)=>t.slice(e,c(r)?r:1/0))),D=v(0),_=S(1,null),N=o(((e,r)=>e+r)),B=o(((e,r)=>r-e)),C=e=>o(((r,t)=>e(t,r))),U=e=>n(e)||(e=>void 0===e)(e),$=e=>e.length,z=e=>()=>e,F=e=>e,I=e=>!e,K=e=>(...r)=>{const t=e(...r);return a(t)&&t.$args_left?K(t):I(t)},L=e=>Object.entries(e),T=o(((e,r)=>e.test(r))),X=o(((e,r)=>(e(r),r))),M=o(((e,r)=>[...r,e])),G=o(((e,r)=>r.split(e))),H=z(!0),J=z(!1),Q=o(((e,r)=>V(N(e),r-e))),R=o(((e,r)=>e.filter(C(P)(r)))),V=o(((e,r)=>[...Array(r)].map(((r,t)=>e(t))))),W=o(((e,r)=>e>r)),Y=o(((e,r)=>e<r)),Z=o(((e,r)=>r>=e)),ee=o(((e,r)=>r<=e)),re=o(((e,r)=>r.sort(e))),te=o(((e,r)=>r.find(e))),se=o(((e,r)=>r.findIndex(e))),oe=o(((e,r)=>se(w(e),r))),pe=o(((e,r)=>{for(const[t,s]of e)if(t(r))return s(r)})),ne=o(((e,r,t)=>({...t,[e]:r}))),ce=o(((e,r,t)=>E((s=>{return ne(s,$(e)<2?r:ce(S(1,null,e),r,(o=t[s],n(o)||"object"!==p(o)?{}:t[s])),t);var o}),D)(e))),xe=o(((e,r)=>r.every(e))),ae=o(((e,r)=>r.some(e))),le=o(((e,r)=>e.every((e=>e(r))))),ie=o(((e,r)=>e.some((e=>e(r))))),ue=o(((e,r)=>r[e])),fe=o(((e,r,t)=>w(t[e],r))),de=o(((e,r,t)=>w(r[e],t[e]))),he=o(((e,r,t)=>q($,(()=>U(t)?e:E(q(U,z(e),(t=>he(e,S(1,null,r),t))),C(ue)(t),D)(r)),z(t),r))),me=he(undefined),ge=o(((e,r,t)=>w(me(e,t),r))),ye=o(((e,r,t)=>w(me(e,r),me(e,t)))),be=/^(.*?)(8|16|32|64)(Clamped)?Array$/,je=e=>{const r=i(e);switch(r){case"Null":return e;case"Array":return Pe(je,e);case"Object":const t={};for(let r in e)t[r]=je(e[r]);return t;case"String":case"Number":case"Boolean":case"Symbol":return e;default:return be.test(r)?Pe(je,e):e}},Oe=o(((e,r,t)=>d(e,je(r),t))),we=o(((e,r)=>Ne(e,r))),qe=o(((e,r)=>{const t={};for(const s of e)s in r&&(t[s]=r[s]);return t})),Ae=o(((e,r)=>Ne(((r,t)=>!P(t,e)),r))),Ee=e=>Oe(((e,r)=>ne(...r,e)),{},e),ke=o(((e,r)=>e.concat(r))),ve=o(((e,r)=>r.join(e))),Pe=o(((e,r)=>r.map(e))),Se=o(((e,r)=>r.forEach(e))),De=o(((e,r,t)=>r(t)&&e(t))),_e=o(((e,r,t)=>t.replace(e,r))),Ne=o(((e,r)=>x(r)?r.filter(e):E(Ee,Ne((([r,t])=>e(t,r))),L)(r))),Be=o(((e,r)=>Object.assign({},e,r))),Ce=o(((e,r)=>m(je(e),je(r)))),Ue=o(((e,r)=>g(je(e),je(r)))),$e=o(((e,r)=>y(je(e),je(r)))),ze=o(((e,r,t)=>ne(e,r(t[e]),t))),Fe=o(((e,r)=>b(e,Object.assign({},r)))),Ie=(()=>{const e=async(r,t,s)=>{s<t.length&&(await r(t[s]),await e(r,t,++s))};return o(((r,t)=>e(r,t,0)))})(),Ke=o(((e,r)=>Promise.all(r.map(e)))),Le=(()=>{const e=async(r,t,s)=>~s?await e(r,await r[s](t),--s):t;return(...r)=>t=>e(r,t,r.length-1)})(),Te=F,Xe=F,Me=F;exports.F=J,exports.T=H,exports.__=e,exports.add=N,exports.all=xe,exports.allPass=le,exports.always=z,exports.any=ae,exports.anyPass=ie,exports.append=M,exports.assoc=ne,exports.assocPath=ce,exports.bind=k,exports.both=De,exports.clone=je,exports.complement=K,exports.compose=E,exports.composeAsync=Le,exports.concat=ke,exports.cond=pe,exports.curry=o,exports.echo=Me,exports.empty=e=>{switch(i(e)){case"String":return"";case"Object":return{};case"Array":return[];default:return}},exports.equals=w,exports.explore=(e,r="log")=>X((t=>console[r](e,t))),exports.filter=Ne,exports.find=te,exports.findIndex=se,exports.flip=C,exports.forEach=Se,exports.forEachAsync=Ke,exports.forEachSerial=Ie,exports.fromPairs=Ee,exports.genBy=V,exports.getTmpl=e=>{const r=[],t=[],s=e.length;let o,p,n=0,c=0,x=!1;for(n=0;n<s;n++)switch(o=e[n],o){case"{":x=!0,c=n;break;case"}":x=!1,r.push(""),t.push(e.slice(c+1,n));break;default:x||(p=r.length-1,p<0&&(r.push(""),p++),r[p]+=o)}return e=>{const s=[],o=r.length-1;for(const p in r)n=+p,s.push(r[n]),n!==o&&s.push(me(t[n].split("."),e));return s.join("")}},exports.gt=W,exports.gte=Z,exports.head=D,exports.identity=F,exports.ifElse=q,exports.includes=P,exports.indexOf=oe,exports.intersection=R,exports.isEmpty=e=>{switch(i(e)){case"String":case"Array":return 0==$(e);case"Object":for(const r in e)return!1;return!0;default:return null}},exports.isNil=U,exports.join=ve,exports.keys=e=>Object.keys(e),exports.last=e=>e[$(e)-1],exports.length=$,exports.lt=Y,exports.lte=ee,exports.map=Pe,exports.mapKeys=Fe,exports.memoize=e=>{let r,t=!1;return()=>t?r:(t=!0,r=e())},exports.mergeDeep=Ce,exports.mergeDeepAdd=$e,exports.mergeDeepX=Ue,exports.mergeShallow=Be,exports.mirror=Te,exports.not=I,exports.nth=v,exports.omit=Ae,exports.once=e=>{let r,t=!1;return(...s)=>t?r:(t=!0,r=e(...s))},exports.overProp=ze,exports.path=me,exports.pathEq=ge,exports.pathOr=he,exports.pathsEq=ye,exports.pick=qe,exports.pickBy=we,exports.prop=ue,exports.propEq=fe,exports.propsEq=de,exports.qappend=u,exports.qassoc=f,exports.qfilter=j,exports.qindexOf=O,exports.qmapKeys=b,exports.qmergeDeep=m,exports.qmergeDeepAdd=y,exports.qmergeDeepX=g,exports.qreduce=d,exports.range=Q,exports.reduce=Oe,exports.reflect=Xe,exports.replace=_e,exports.reverse=e=>E((r=>Oe(((t,s,o)=>u(e[r-o],t)),[],e)),N(-1),$)(e),exports.sizeof=e=>{if("Object"===i(e)){let r=0;for(let t in e)r++;return r}return $(e)},exports.slice=S,exports.sort=re,exports.split=G,exports.subtract=B,exports.tail=_,exports.tap=X,exports.test=T,exports.toLower=e=>e.toLowerCase(),exports.toPairs=L,exports.toUpper=e=>e.toUpperCase(),exports.trim=e=>e.trim(),exports.type=i,exports.uniq=e=>d(((e,r)=>P(r,e)?e:u(r,e)),[],e),exports.values=e=>Object.values(e),exports.waitAll=e=>Promise.all(e),exports.when=A;
1
+ "use strict";const e=Symbol("Placeholder"),r=r=>{let t=0;for(const s of r)s!==e&&t++;return t},t=(r,t)=>{const s=r.length,o=r.slice(),n=t.length;let p=n,c=0;for(;p&&c<s;c++)o[c]===e&&(o[c]=t[n-p],p--);for(c=s;p;c++,p--)o[c]=t[n-p];return o},s=(e,o,n)=>{const p=e.length-o.length-r(n);if(p<1)return e(...t(o,n));{const r=(...r)=>s(e,t(o,n),r);return r.$args_left=p,r}},o=e=>(...t)=>e.length>r(t)?s(e,[],t):e(...t),n=r=>function(t){return t===e?r:r(t)};function p(r){return function(t,s){const o=t===e,p=arguments.length;if(1===p&&o)throw new Error("Senseless placeholder usage.");return arguments.length>1?o?n((e=>r(e,s))):r(t,s):e=>r(t,e)}}function c(e){return o(e)}const a=void 0,x=1/0,l=e=>typeof e,i=e=>null===e,u=e=>"number"==l(e),f=e=>Array.isArray(e),h=e=>"function"===l(e),m={u:"U",b:"B",n:"N",s:"S",f:"F"},d=e=>{const r=l(e);return"object"===r?i(e)?"Null":e.constructor.name:m[r[0]]+r.slice(1)},y=p(((e,r)=>(r.push(e),r))),g=c(((e,r,t)=>(t[e]=r,t))),b=c(((e,r,t)=>t.reduce(e,r))),w=c(((e,r,t)=>{for(let s in t)switch(d(t[s])){case"Array":if(e>1&&"Array"===d(r[s]))switch(e){case 2:const o=r[s],n=t[s];for(const r in n)o[r]?w(e,o[r],n[r]):o[r]=n[r];break;case 3:r[s].push(...t[s])}else r[s]=t[s];break;case"Object":if("Object"===d(r[s])){w(e,r[s],t[s]);break}default:r[s]=t[s]}return r})),j=w(1),O=w(2),q=w(3),A=p(((e,r)=>{let t,s,o,n;for(t in e)s=e[t],[o,n]=h(s)?s(r):[s,r[t]],r[o]=n,t!==o&&delete r[t];return r})),E=p(((e,r)=>{const t=f(r);for(let s in r)e(r[s],s)||(t?r.splice(s,1):delete r[s]);return r})),S=p(((e,r)=>r.indexOf(e))),k=p(((e,r)=>{const t=d(e);if(t===d(r)&&("Object"===t||"Array"==t)){if(i(e)||i(r))return e===r;if(e===r)return!0;for(const t of[e,r])for(const s in t)if(!(t===r&&s in e||t===e&&s in r&&k(e[s],r[s])))return!1;return!0}return e===r})),P=o(((e,r,t,s)=>e(s)?r(s):t(s))),v=c(((e,r,t)=>P(e,r,X,t))),D=(...r)=>(t=Symbol())=>{for(let s=K(r)-1;s>-1;s--)t=t===e?r[s]():r[s](t);return t},N=p(((e,r)=>e.bind(r))),B=p(((e,r)=>r[e])),_=p(((e,r)=>{if((e=>"string"===l(e))(r))return r.includes(e);for(const t of r)if(k(t,e))return!0;return!1})),C=c(((e,r,t)=>t.slice(e,u(r)?r:x))),T=B(0),U=C(1,x),$=p(((e,r)=>e+r)),z=p(((e,r)=>r-e)),F=e=>o(((r,t)=>e(t,r))),I=e=>i(e)||(e=>e===a)(e),K=e=>e.length,L=e=>()=>e,X=e=>e,G=e=>!e,H=e=>(...r)=>{const t=e(...r);return h(t)&&t.$args_left?H(t):G(t)},J=e=>Object.entries(e),M=p(((e,r)=>e.test(r))),Q=p(((e,r)=>(e(r),r))),R=p(((e,r)=>[...r,e])),V=p(((e,r)=>r.split(e))),W=L(!0),Y=L(!1),Z=p(((e,r)=>re($(e),r-e))),ee=p(((e,r)=>e.filter(F(_)(r)))),re=p(((e,r)=>[...Array(r)].map(((r,t)=>e(t))))),te=p(((e,r)=>e>r)),se=p(((e,r)=>e<r)),oe=p(((e,r)=>r>=e)),ne=p(((e,r)=>r<=e)),pe=p(((e,r)=>r.sort(e))),ce=p(((e,r)=>r.find(e))),ae=p(((e,r)=>r.findIndex(e))),xe=p(((e,r)=>ae(k(e),r))),le=p(((e,r)=>{for(const[t,s]of e)if(t(r))return s(r)})),ie=c(((e,r,t)=>({...t,[e]:r}))),ue=c(((e,r,t)=>D((s=>{return ie(s,K(e)<2?r:ue(C(1,x,e),r,(o=t[s],i(o)||"object"!==l(o)?{}:t[s])),t);var o}),T)(e))),fe=p(((e,r)=>r.every(e))),he=p(((e,r)=>r.some(e))),me=p(((e,r)=>e.every((e=>e(r))))),de=p(((e,r)=>e.some((e=>e(r))))),ye=p(((e,r)=>r[e])),ge=c(((e,r,t)=>k(t[e],r))),be=c(((e,r,t)=>k(r[e],t[e]))),we=c(((e,r,t)=>P(K,(()=>I(t)?e:D(P(I,L(e),(t=>we(e,C(1,x,r),t))),F(ye)(t),T)(r)),L(t),r))),je=we(a),Oe=c(((e,r,t)=>k(je(e,t),r))),qe=c(((e,r,t)=>k(je(e,r),je(e,t)))),Ae=/^(.*?)(8|16|32|64)(Clamped)?Array$/,Ee=(e,r=!1)=>{const t=d(e);switch(t){case"Null":case"String":case"Number":case"Boolean":case"Symbol":return e;case"Array":return r?[...e]:_e(Ee,e);case"Object":if(r)return{...e};const s={};for(let r in e)s[r]=Ee(e[r]);return s;default:return Ae.test(t)?e.constructor.from(e):e}},Se=c(((e,r,t)=>b(e,Ee(r),t))),ke=p(((e,r)=>$e(e,r))),Pe=p(((e,r)=>{const t={};for(const s of e)s in r&&(t[s]=r[s]);return t})),ve=p(((e,r)=>$e(((r,t)=>!_(t,e)),r))),De=e=>Se(((e,r)=>ie(...r,e)),{},e),Ne=p(((e,r)=>e.concat(r))),Be=p(((e,r)=>r.join(e))),_e=p(((e,r)=>r.map(e))),Ce=p(((e,r)=>r.forEach(e))),Te=c(((e,r,t)=>r(t)&&e(t))),Ue=c(((e,r,t)=>t.replace(e,r))),$e=p(((e,r)=>f(r)?r.filter(e):D(De,$e((([r,t])=>e(t,r))),J)(r))),ze=p(((e,r)=>Object.assign({},e,r))),Fe=p(((e,r)=>j(Ee(e),Ee(r)))),Ie=p(((e,r)=>O(Ee(e),Ee(r)))),Ke=p(((e,r)=>q(Ee(e),Ee(r)))),Le=c(((e,r,t)=>ie(e,r(t[e]),t))),Xe=p(((e,r)=>A(e,Object.assign({},r)))),Ge=(()=>{const e=async(r,t,s)=>{s<t.length&&(await r(t[s]),await e(r,t,++s))};return p(((r,t)=>e(r,t,0)))})(),He=p((async(e,r)=>(await e(r),r))),Je=p(((e,r)=>Promise.all(r.map(e)))),Me=(()=>{const e=async(r,t,s)=>~s?await e(r,await r[s](t),--s):t;return(...r)=>t=>e(r,t,r.length-1)})(),Qe=X,Re=X,Ve=X;exports.F=Y,exports.T=W,exports.__=e,exports.add=$,exports.all=fe,exports.allPass=me,exports.always=L,exports.any=he,exports.anyPass=de,exports.append=R,exports.assoc=ie,exports.assocPath=ue,exports.bind=N,exports.both=Te,exports.clone=Ee,exports.cloneShallow=e=>Ee(e,!0),exports.complement=H,exports.compose=D,exports.composeAsync=Me,exports.concat=Ne,exports.cond=le,exports.curry=o,exports.curry2=p,exports.curry3=c,exports.echo=Ve,exports.empty=e=>{switch(d(e)){case"String":return"";case"Object":return{};case"Array":return[];default:return a}},exports.equals=k,exports.explore=(e,r="log")=>Q((t=>console[r](e,t))),exports.filter=$e,exports.find=ce,exports.findIndex=ae,exports.flip=F,exports.forEach=Ce,exports.forEachAsync=Je,exports.forEachSerial=Ge,exports.fromPairs=De,exports.genBy=re,exports.getTmpl=e=>{const r=[],t=[],s=e.length;let o,n,p=0,c=0,a=!1;for(p=0;p<s;p++)switch(o=e[p],o){case"{":a=!0,c=p;break;case"}":a=!1,r.push(""),t.push(e.slice(c+1,p));break;default:a||(n=r.length-1,n<0&&(r.push(""),n++),r[n]+=o)}return e=>{const s=[],o=r.length-1;for(const n in r)p=+n,s.push(r[p]),p!==o&&s.push(je(t[p].split("."),e));return s.join("")}},exports.gt=te,exports.gte=oe,exports.head=T,exports.identity=X,exports.ifElse=P,exports.includes=_,exports.indexOf=xe,exports.intersection=ee,exports.isEmpty=e=>{switch(d(e)){case"String":case"Array":return 0==K(e);case"Object":for(const r in e)return!1;return!0;default:return null}},exports.isNil=I,exports.join=Be,exports.keys=e=>Object.keys(e),exports.last=e=>e[K(e)-1],exports.length=K,exports.lt=se,exports.lte=ne,exports.map=_e,exports.mapKeys=Xe,exports.memoize=e=>{let r,t=!1;return()=>t?r:(t=!0,r=e())},exports.mergeDeep=Fe,exports.mergeDeepAdd=Ke,exports.mergeDeepX=Ie,exports.mergeShallow=ze,exports.mirror=Qe,exports.not=G,exports.nth=B,exports.omit=ve,exports.once=e=>{let r,t=!1;return(...s)=>t?r:(t=!0,r=e(...s))},exports.overProp=Le,exports.path=je,exports.pathEq=Oe,exports.pathOr=we,exports.pathsEq=qe,exports.pick=Pe,exports.pickBy=ke,exports.prop=ye,exports.propEq=ge,exports.propsEq=be,exports.qappend=y,exports.qassoc=g,exports.qfilter=E,exports.qindexOf=S,exports.qmapKeys=A,exports.qmergeDeep=j,exports.qmergeDeepAdd=q,exports.qmergeDeepX=O,exports.qreduce=b,exports.range=Z,exports.reduce=Se,exports.reflect=Re,exports.replace=Ue,exports.reverse=e=>D((r=>Se(((t,s,o)=>y(e[r-o],t)),[],e)),$(-1),K)(e),exports.sizeof=e=>{if("Object"===d(e)){let r=0;for(let t in e)r++;return r}return K(e)},exports.slice=C,exports.sort=pe,exports.split=V,exports.subtract=z,exports.tail=U,exports.tap=Q,exports.test=M,exports.toLower=e=>e.toLowerCase(),exports.toPairs=J,exports.toUpper=e=>e.toUpperCase(),exports.trim=e=>e.trim(),exports.type=d,exports.uncurry=e=>(...r)=>b(((e,r)=>e?e(r):e),e,r),exports.uniq=e=>b(((e,r)=>_(r,e)?e:y(r,e)),[],e),exports.values=e=>Object.values(e),exports.waitAll=e=>Promise.all(e),exports.waitTap=He,exports.when=v;
package/dist/es/curry.js CHANGED
@@ -1,4 +1,4 @@
1
- export const __ = (function Placeholder() { });
1
+ export const __ = Symbol('Placeholder');
2
2
  const countArgs = (s) => {
3
3
  let i = 0;
4
4
  for (const v of s)
@@ -38,3 +38,31 @@ const _curry = (fn, args, new_args) => {
38
38
  export const curry = ((fn) => ((...args) => fn.length > countArgs(args)
39
39
  ? _curry(fn, [], args)
40
40
  : fn(...args)));
41
+ const endlessph = (fn) => {
42
+ function _endlessph(a) {
43
+ return a === __ ? fn : fn(a);
44
+ }
45
+ return _endlessph;
46
+ };
47
+ export function curry2(fn) {
48
+ function curried2(a, b) {
49
+ const withPlaceholder1 = a === __;
50
+ const aln = arguments.length;
51
+ if (aln === 1 && withPlaceholder1)
52
+ throw new Error('Senseless placeholder usage.');
53
+ return arguments.length > 1
54
+ ? withPlaceholder1
55
+ ? endlessph((a) => fn(a, b))
56
+ : fn(a, b)
57
+ : (b) => fn(a, b);
58
+ }
59
+ return curried2;
60
+ }
61
+ export function curry3(fn) {
62
+ // type p0 = Parameters<Func>[0]
63
+ // type p1 = Parameters<Func>[1]
64
+ // type p2 = Parameters<Func>[2]
65
+ // type ReturnT = ReturnType<Func>
66
+ // TODO: optimize.
67
+ return curry(fn);
68
+ }
package/dist/es/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './curry';
2
+ export * from './uncurry';
2
3
  export * from './common';
3
4
  export * from './safe';
4
5
  export * from './quick';
package/dist/es/quick.js CHANGED
@@ -1,14 +1,14 @@
1
- import { curry } from "./curry";
1
+ import { curry2, curry3 } from "./curry";
2
2
  import { type } from "./common";
3
3
  import { isFunc, isArray } from "./utils";
4
- export const qappend = curry((s, xs) => { xs.push(s); return xs; });
5
- export const qassoc = curry((prop, v, obj) => {
4
+ export const qappend = curry2((s, xs) => { xs.push(s); return xs; });
5
+ export const qassoc = curry3((prop, v, obj) => {
6
6
  obj[prop] = v;
7
7
  return obj;
8
8
  });
9
- export const qreduce = curry((fn, accum, arr) => arr.reduce(fn, accum));
9
+ export const qreduce = curry3((fn, accum, arr) => arr.reduce(fn, accum));
10
10
  // strategy is for arrays: 1->clean, 2->merge, 3->push.
11
- const mergeDeep = curry((strategy, o1, o2) => {
11
+ const mergeDeep = curry3((strategy, o1, o2) => {
12
12
  for (let k in o2) {
13
13
  switch (type(o2[k])) {
14
14
  case 'Array':
@@ -49,7 +49,7 @@ export const qmergeDeep = mergeDeep(1);
49
49
  export const qmergeDeepX = mergeDeep(2);
50
50
  export const qmergeDeepAdd = mergeDeep(3);
51
51
  /** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
52
- export const qmapKeys = curry((keyMap, o) => {
52
+ export const qmapKeys = curry2((keyMap, o) => {
53
53
  let k, mapped, newKey, newValue;
54
54
  for (k in keyMap) {
55
55
  mapped = keyMap[k];
@@ -63,7 +63,7 @@ export const qmapKeys = curry((keyMap, o) => {
63
63
  }
64
64
  return o;
65
65
  });
66
- export const qfilter = curry((cond, data) => {
66
+ export const qfilter = curry2((cond, data) => {
67
67
  const isArr = isArray(data);
68
68
  for (let k in data) {
69
69
  if (!cond(data[k], k)) {
@@ -79,4 +79,4 @@ export const qfilter = curry((cond, data) => {
79
79
  return data;
80
80
  });
81
81
  /** @deprecated */
82
- export const qindexOf = curry((x, xs) => xs.indexOf(x));
82
+ export const qindexOf = curry2((x, xs) => xs.indexOf(x));
package/dist/es/safe.js CHANGED
@@ -1,9 +1,9 @@
1
- import { __, curry } from './curry';
2
- import { isNum, nul, isUndef, undef, isNull, isArray, isFunc, isStr, isObj } from './utils';
1
+ import { __, curry, curry2, curry3 } from './curry';
2
+ import { isNum, isUndef, undef, isNull, isArray, isFunc, isStr, isObj, inf } from './utils';
3
3
  import { qmergeDeep, qreduce, qappend, qmapKeys, qmergeDeepX, qmergeDeepAdd } from './quick';
4
4
  import { type } from './common';
5
5
  // over, lensProp
6
- export const equals = curry((a, b) => {
6
+ export const equals = curry2((a, b) => {
7
7
  const typea = type(a);
8
8
  if (typea === type(b) && (typea === 'Object' || typea == 'Array')) {
9
9
  if (isNull(a) || isNull(b)) {
@@ -25,16 +25,17 @@ export const equals = curry((a, b) => {
25
25
  return a === b;
26
26
  });
27
27
  export const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
28
- export const when = curry((cond, pipe, s) => ifElse(cond, pipe, identity, s));
29
- export const compose = ((...fns) => (s = __) => {
28
+ export const when = curry3((cond, pipe, s) => ifElse(cond, pipe, identity, s));
29
+ export const compose = ((...fns) => (s = Symbol()) => {
30
30
  for (let i = length(fns) - 1; i > -1; i--) {
31
31
  s = s === __ ? fns[i]() : fns[i](s);
32
32
  }
33
33
  return s;
34
- }); // as F.Compose
35
- export const bind = curry((fn, context) => fn.bind(context));
36
- export const nth = curry((i, data) => data[i]);
37
- export const includes = curry((s, ss) => {
34
+ });
35
+ export const bind = curry2((fn, context) => fn.bind(context));
36
+ const _nth = (i, data) => data[i];
37
+ export const nth = curry2(_nth);
38
+ export const includes = curry2((s, ss) => {
38
39
  if (isStr(ss)) {
39
40
  return ss.includes(s);
40
41
  }
@@ -47,11 +48,11 @@ export const includes = curry((s, ss) => {
47
48
  return false;
48
49
  }
49
50
  });
50
- export const slice = curry((from, to, o) => o.slice(from, (isNum(to) ? to : Infinity)));
51
+ export const slice = curry3((from, to, o) => o.slice(from, (isNum(to) ? to : inf)));
51
52
  export const head = nth(0);
52
- export const tail = slice(1, nul);
53
- export const add = curry((n, m) => n + m);
54
- export const subtract = curry((n, m) => m - n);
53
+ export const tail = slice(1, inf); // typeshit.
54
+ export const add = curry2((n, m) => n + m);
55
+ export const subtract = curry2((n, m) => m - n);
55
56
  export const flip = (fn) => curry((b, a) => fn(a, b));
56
57
  export const isNil = (s) => isNull(s) || isUndef(s);
57
58
  export const length = (s) => s.length;
@@ -67,10 +68,10 @@ export const complement = (fn) => (...args) => {
67
68
  export const keys = (o) => Object.keys(o);
68
69
  export const values = (o) => Object.values(o);
69
70
  export const toPairs = (o) => Object.entries(o);
70
- export const test = curry((re, s) => re.test(s));
71
- export const tap = curry((fn, s) => { fn(s); return s; });
72
- export const append = curry((s, xs) => [...xs, s]);
73
- export const split = curry((s, xs) => xs.split(s));
71
+ export const test = curry2((re, s) => re.test(s));
72
+ export const tap = curry2((fn, s) => { fn(s); return s; });
73
+ export const append = curry2((s, xs) => [...xs, s]);
74
+ export const split = curry2((s, xs) => xs.split(s));
74
75
  export const T = always(true);
75
76
  export const F = always(false);
76
77
  export const sizeof = (s) => {
@@ -83,10 +84,10 @@ export const sizeof = (s) => {
83
84
  else
84
85
  return length(s);
85
86
  };
86
- export const range = curry((from, to) => genBy(add(from), to - from));
87
+ export const range = curry2((from, to) => genBy(add(from), to - from));
87
88
  export const uniq = (xs) => qreduce((accum, x) => includes(x, accum) ? accum : qappend(x, accum), [], xs);
88
- export const intersection = curry((xs1, xs2) => xs1.filter(flip(includes)(xs2)));
89
- export const genBy = curry((generator, length) => [...Array(length)].map((_, i) => generator(i)));
89
+ export const intersection = curry2((xs1, xs2) => xs1.filter(flip(includes)(xs2)));
90
+ export const genBy = curry2((generator, length) => [...Array(length)].map((_, i) => generator(i)));
90
91
  export const once = (fn) => {
91
92
  let done = false, cache;
92
93
  return (...args) => {
@@ -100,50 +101,51 @@ export const once = (fn) => {
100
101
  };
101
102
  };
102
103
  export const reverse = (xs) => compose((ln) => reduce((nxs, _, i) => qappend(xs[ln - i], nxs), [], xs), add(-1), length)(xs);
103
- export const gt = curry((a, b) => a > b);
104
- export const lt = curry((a, b) => a < b);
105
- export const gte = curry((a, b) => b >= a);
106
- export const lte = curry((a, b) => b <= a);
107
- // : <U=any>(sortFn: (v: U)=>-1|1, xs: U[]) => U[]
108
- export const sort = curry((sortFn, xs) => xs.sort(sortFn));
109
- export const find = curry((fn, s) => s.find(fn));
110
- export const findIndex = curry((fn, s) => s.findIndex(fn));
111
- export const indexOf = curry((x, xs) => findIndex(equals(x), xs));
104
+ export const gt = curry2((a, b) => a > b);
105
+ export const lt = curry2((a, b) => a < b);
106
+ export const gte = curry2((a, b) => b >= a);
107
+ export const lte = curry2((a, b) => b <= a);
108
+ export const sort = curry2((sortFn, xs) => xs.sort(sortFn));
109
+ export const find = curry2((fn, s) => s.find(fn));
110
+ export const findIndex = curry2((fn, s) => s.findIndex(fn));
111
+ export const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
112
112
  export const explore = (caption, level = 'log') => tap((v) => console[level](caption, v));
113
- export const cond = curry((pairs, s) => {
113
+ export const cond = curry2((pairs, s) => {
114
114
  for (const [cond, fn] of pairs) {
115
115
  if (cond(s)) {
116
116
  return fn(s);
117
117
  }
118
118
  }
119
119
  });
120
- export const assoc = curry((prop, v, obj) => ({
120
+ export const assoc = curry3((prop, v, obj) => ({
121
121
  ...obj,
122
122
  [prop]: v
123
123
  }));
124
- export const assocPath = curry((_path, v, o) => compose((first) => assoc(first, length(_path) < 2
124
+ export const assocPath = curry3((_path, v, o) => compose((first) => assoc(first, length(_path) < 2
125
125
  ? v
126
- : assocPath(slice(1, null, _path), v, isObj(o[first]) ? o[first] : {}), o), head)(_path));
127
- export const all = curry((pred, xs) => xs.every(pred));
128
- export const any = curry((pred, xs) => xs.some(pred));
129
- export const allPass = curry((preds, x) => preds.every((pred) => pred(x)));
130
- export const anyPass = curry((preds, x) => preds.some((pred) => pred(x)));
131
- export const prop = curry((key, o) => o[key]);
132
- export const propEq = curry((key, value, o) => equals(o[key], value));
133
- export const propsEq = curry((key, o1, o2) => equals(o1[key], o2[key]));
134
- export const pathOr = curry((_default, path, o) => ifElse(length, () => isNil(o)
126
+ : assocPath(slice(1, inf, _path), v, isObj(o[first]) ? o[first] : {}), o), head)(_path));
127
+ export const all = curry2((pred, xs) => xs.every(pred));
128
+ export const any = curry2((pred, xs) => xs.some(pred));
129
+ export const allPass = curry2((preds, x) => preds.every((pred) => pred(x)));
130
+ export const anyPass = curry2((preds, x) => preds.some((pred) => pred(x)));
131
+ export const prop = curry2((key, o) => o[key]);
132
+ export const propEq = curry3((key, value, o) => equals(o[key], value));
133
+ export const propsEq = curry3((key, o1, o2) => equals(o1[key], o2[key]));
134
+ export const pathOr = curry3((_default, path, o) => ifElse(length, () => isNil(o)
135
135
  ? _default
136
- : compose(ifElse(isNil, always(_default), (o) => pathOr(_default, slice(1, nul, path), o)), flip(prop)(o), head)(path), always(o), path));
136
+ : compose(ifElse(isNil, always(_default), (o) => pathOr(_default, slice(1, inf, path), o)), flip(prop)(o), head)(path), always(o), path));
137
137
  export const path = pathOr(undef);
138
- export const pathEq = curry((_path, value, o) => equals(path(_path, o), value));
139
- export const pathsEq = curry((_path, o1, o2) => equals(path(_path, o1), path(_path, o2)));
138
+ export const pathEq = curry3((_path, value, o) => equals(path(_path, o), value));
139
+ export const pathsEq = curry3((_path, o1, o2) => equals(path(_path, o1), path(_path, o2)));
140
140
  const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
141
- export const clone = (s) => {
141
+ export const clone = (s, shallow = false) => {
142
142
  const t = type(s);
143
143
  switch (t) {
144
144
  case 'Null': return s;
145
- case 'Array': return map(clone, s);
145
+ case 'Array': return shallow ? [...s] : map(clone, s);
146
146
  case 'Object':
147
+ if (shallow)
148
+ return { ...s };
147
149
  const out = {};
148
150
  for (let k in s) {
149
151
  out[k] = clone(s[k]);
@@ -155,12 +157,13 @@ export const clone = (s) => {
155
157
  case 'Symbol':
156
158
  return s;
157
159
  default:
158
- return typed_arr_re.test(t) ? map(clone, s) : s;
160
+ return typed_arr_re.test(t) ? s.constructor.from(s) : s;
159
161
  }
160
162
  };
161
- export const reduce = curry((fn, accum, arr) => qreduce(fn, clone(accum), arr));
162
- export const pickBy = curry((cond, o) => filter(cond, o));
163
- export const pick = curry((props, o) => {
163
+ export const cloneShallow = (s) => clone(s, true);
164
+ export const reduce = curry3((fn, accum, arr) => qreduce(fn, clone(accum), arr));
165
+ export const pickBy = curry2((cond, o) => filter(cond, o));
166
+ export const pick = curry2((props, o) => {
164
167
  const out = {};
165
168
  for (const p of props) {
166
169
  if (p in o) {
@@ -169,13 +172,13 @@ export const pick = curry((props, o) => {
169
172
  }
170
173
  return out;
171
174
  });
172
- export const omit = curry((props, o) => filter((_, k) => !includes(k, props), o));
175
+ export const omit = curry2((props, o) => filter((_, k) => !includes(k, props), o));
173
176
  export const fromPairs = (pairs) => reduce((o, pair) => assoc(...pair, o), {}, pairs);
174
- export const concat = curry(((a, b) => a.concat(b)));
175
- export const join = curry((delimeter, arr) => arr.join(delimeter));
176
- export const map = curry((pipe, arr) => arr.map(pipe));
177
- export const forEach = curry((pipe, arr) => arr.forEach(pipe));
178
- export const both = curry((cond1, cond2, s) => cond2(s) && cond1(s));
177
+ export const concat = curry2(((a, b) => a.concat(b)));
178
+ export const join = curry2((delimeter, arr) => arr.join(delimeter));
179
+ export const map = curry2((pipe, arr) => arr.map(pipe));
180
+ export const forEach = curry2((pipe, arr) => arr.forEach(pipe));
181
+ export const both = curry3((cond1, cond2, s) => cond2(s) && cond1(s));
179
182
  export const isEmpty = (s) => {
180
183
  switch (type(s)) {
181
184
  case 'String':
@@ -195,8 +198,8 @@ export const empty = (s) => {
195
198
  default: return undef;
196
199
  }
197
200
  };
198
- export const replace = curry((a, b, where) => where.replace(a, b));
199
- export const filter = curry((cond, data) => isArray(data)
201
+ export const replace = curry3((a, b, where) => where.replace(a, b));
202
+ export const filter = curry2((cond, data) => isArray(data)
200
203
  ? data.filter(cond)
201
204
  : compose(fromPairs, filter(([k, v]) => cond(v, k)), toPairs)(data));
202
205
  export const memoize = (fn) => {
@@ -204,13 +207,13 @@ export const memoize = (fn) => {
204
207
  let cached = false;
205
208
  return () => cached ? cache : (cached = true, cache = fn());
206
209
  };
207
- export const mergeShallow = curry((o1, o2) => Object.assign({}, o1, o2));
208
- export const mergeDeep = curry((a, b) => qmergeDeep(clone(a), clone(b)));
209
- export const mergeDeepX = curry((a, b) => qmergeDeepX(clone(a), clone(b)));
210
- export const mergeDeepAdd = curry((a, b) => qmergeDeepAdd(clone(a), clone(b)));
211
- export const overProp = curry((prop, pipe, data) => assoc(prop, pipe(data[prop]), data));
210
+ export const mergeShallow = curry2((o1, o2) => Object.assign({}, o1, o2));
211
+ export const mergeDeep = curry2((a, b) => qmergeDeep(clone(a), clone(b)));
212
+ export const mergeDeepX = curry2((a, b) => qmergeDeepX(clone(a), clone(b)));
213
+ export const mergeDeepAdd = curry2((a, b) => qmergeDeepAdd(clone(a), clone(b)));
214
+ export const overProp = curry3((prop, pipe, data) => assoc(prop, pipe(data[prop]), data));
212
215
  /** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
213
- export const mapKeys = curry((keyMap, o) => qmapKeys(keyMap, Object.assign({}, o)));
216
+ export const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, Object.assign({}, o)));
214
217
  // ASYNCS
215
218
  /** One promise waits for another. */
216
219
  export const forEachSerial = (() => {
@@ -220,12 +223,13 @@ export const forEachSerial = (() => {
220
223
  await pipe(fn, items, ++i);
221
224
  }
222
225
  };
223
- return curry((fn, items) => pipe(fn, items, 0));
226
+ return curry2((fn, items) => pipe(fn, items, 0));
224
227
  })();
225
228
  /** Promise.all wrapper for functional pipelining. */
226
229
  export const waitAll = (promises) => Promise.all(promises);
230
+ export const waitTap = curry2(async (fn, s) => { await fn(s); return s; });
227
231
  /** Waits for all promises mapped by the fn. */
228
- export const forEachAsync = curry((fn, items) => Promise.all(items.map(fn)));
232
+ export const forEachAsync = curry2((fn, items) => Promise.all(items.map(fn)));
229
233
  /** The same as compose, but waits for promises in chains and returns a Promise. */
230
234
  export const composeAsync = (() => {
231
235
  const pipe = async (fns, data, i) => ~i ? await pipe(fns, await fns[i](data), --i) : data;
@@ -0,0 +1,3 @@
1
+ import { qreduce } from "./quick";
2
+ // TODO: possibly introduce a second argument limiting unfolding.
3
+ export const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
package/dist/es/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export const undef = undefined;
2
2
  export const nul = null;
3
+ export const inf = Infinity;
3
4
  export const to = (s) => typeof s;
4
5
  export const isNull = (s) => s === nul;
5
6
  export const isUndef = (s) => s === undef;
package/dts-fix.js ADDED
@@ -0,0 +1,11 @@
1
+ import prepend from 'prepend'
2
+  
3
+ const s =
4
+ `import {F as FT} from 'ts-toolbelt'
5
+ export { __ }
6
+ `
7
+
8
+ prepend('./dist/bundle.d.ts', s, function(error) {
9
+     if (error)
10
+         console.error(error.message)
11
+ })
package/package.json CHANGED
@@ -32,14 +32,15 @@
32
32
  "test": "npm run gentypes && npm run prod:cjs && ava",
33
33
  "test:report": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov && codecov",
34
34
  "test:lazy": "ava",
35
- "gentypes": "dts-bundle-generator -o dist/bundle.d.ts src/index.ts",
35
+ "dts-fix": "node dts-fix.js",
36
+ "gentypes": "dts-bundle-generator --no-check -o dist/bundle.d.ts src/index.ts && npm run dts-fix",
36
37
  "dev": "cross-env NODE_ENV=development BUILD=es rollup -c",
37
38
  "prod:cjs": "cross-env NODE_ENV=production BUILD=cjs rollup -c",
38
39
  "prod:es": "cross-env NODE_ENV=production tsc",
39
40
  "prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
40
41
  "all": "npm run dev && npm run prod"
41
42
  },
42
- "version": "0.13.0b1",
43
+ "version": "0.13.0b10",
43
44
  "ava": {
44
45
  "files": [
45
46
  "./test/specs/*.ts"
@@ -53,6 +54,9 @@
53
54
  "ts-node/register"
54
55
  ]
55
56
  },
57
+ "dependencies": {
58
+ "ts-toolbelt": "^9.6.0"
59
+ },
56
60
  "devDependencies": {
57
61
  "@types/node": "^18.11.10",
58
62
  "ava": "^5.1.0",
@@ -60,6 +64,7 @@
60
64
  "cross-env": "^7.0.3",
61
65
  "dts-bundle-generator": "^7.1.0",
62
66
  "nyc": "^15.1.0",
67
+ "prepend": "^1.0.2",
63
68
  "rollup": "^3.5.1",
64
69
  "rollup-plugin-commonjs": "^10.1.0",
65
70
  "rollup-plugin-node-resolve": "^5.2.0",
@@ -68,7 +73,6 @@
68
73
  "rollup-plugin-terser": "^7.0.2",
69
74
  "rollup-plugin-typescript2": "^0.34.1",
70
75
  "ts-node": "^10.9.1",
71
- "ts-toolbelt": "^9.6.0",
72
76
  "tslint": "^6.1.0",
73
77
  "typescript": "^4.9.3"
74
78
  },
package/src/curry.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { F as FT, A } from 'ts-toolbelt'
1
+ import { F as FT } from 'ts-toolbelt'
2
2
  import { AnyFunc, AnyArgs } from "./types"
3
3
 
4
- export const __ = Symbol('Placeholder') as A.x
4
+ type Placeholder = symbol
5
+ export const __: Placeholder = Symbol('Placeholder')
5
6
 
6
7
  const countArgs = (s: AnyArgs) => {
7
8
  let i = 0
@@ -51,15 +52,12 @@ export const curry = (
51
52
  : fn(...args)
52
53
  ) as FT.Curry<Func>
53
54
  )
54
- // type EndlessPh<Func extends FT.Function, ArgT> =
55
- // (a: ArgT) => ReturnType<Func>
56
- // | ((a: A.x) => EndlessPh<Func, ArgT>)
57
55
  const endlessph = <Func extends FT.Function>(fn: Func) => {
58
56
  type ReturnT = ReturnType<Func>
59
57
  type p0 = Parameters<Func>[0]
60
58
  function _endlessph(a: p0): ReturnT
61
- function _endlessph(a: A.x): Func
62
- function _endlessph(a: p0 | A.x) {
59
+ function _endlessph(a: Placeholder): Func
60
+ function _endlessph(a: p0 | Placeholder) {
63
61
  return a===__ ? fn : fn(a)
64
62
  }
65
63
  return _endlessph
@@ -70,11 +68,11 @@ export function curry2<Func extends Func2>(fn: Func) {
70
68
  type p0 = Parameters<Func>[0]
71
69
  type p1 = Parameters<Func>[1]
72
70
  type ReturnT = ReturnType<Func>
71
+ function curried2( a: Placeholder, b: p1 ): (a: p0) => ReturnT
72
+ function curried2( a: p0, b: Placeholder ): (b: p1) => ReturnT
73
73
  function curried2( a: p0 ): (b: p1) => ReturnT
74
74
  function curried2( a: p0, b: p1 ): ReturnT
75
- function curried2( a: A.x, b: p1 ): (a: p0) => ReturnT
76
- function curried2( a: p0, b: A.x ): (b: p1) => ReturnT
77
- function curried2( a: p0 | A.x, b?: p1 ) {
75
+ function curried2( a: p0 | Placeholder, b?: p1 ) {
78
76
  const withPlaceholder1 = a===__
79
77
  const aln = arguments.length
80
78
  if(aln === 1 && withPlaceholder1)
@@ -95,5 +93,5 @@ export function curry3<Func extends Func3>(fn: Func) {
95
93
  // type p2 = Parameters<Func>[2]
96
94
  // type ReturnT = ReturnType<Func>
97
95
  // TODO: optimize.
98
- return curry(fn)
96
+ return curry(fn) as FT.Curry<Func>
99
97
  }
package/src/quick.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { curry, curry2, curry3 } from "./curry"
1
+ import { curry2, curry3 } from "./curry"
2
2
  import { type } from "./common"
3
3
  import { AnyObject, Reducer, AnyFunc } from "./types"
4
4
  import { isFunc, isArray } from "./utils"
@@ -11,7 +11,7 @@ export const qassoc = curry3(
11
11
  }
12
12
  )
13
13
  export const qreduce = curry3(
14
- (fn: Reducer, accum: any, arr: any[]) =>
14
+ <T>(fn: Reducer, accum: any, arr: T[]) =>
15
15
  arr.reduce(fn, accum)
16
16
  )
17
17
  // strategy is for arrays: 1->clean, 2->merge, 3->push.
package/src/safe.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { __, curry, curry2, curry3 } from './curry'
2
- import { isNum, nul, isUndef, undef, isNull, isArray, isFunc, isStr, isObj } from './utils'
2
+ import { isNum, isUndef, undef, isNull, isArray, isFunc, isStr, isObj, inf } from './utils'
3
3
  import { qmergeDeep, qreduce, qappend, qmapKeys, qmergeDeepX, qmergeDeepAdd } from './quick'
4
4
  import { AnyFunc, Cond, AnyObject, Reducer } from './types'
5
5
  import { type } from './common'
@@ -44,13 +44,14 @@ export const when = curry3(
44
44
  s: any
45
45
  ) => ifElse(cond, pipe, identity, s)
46
46
  )
47
- export const compose: FT.Compose = (
48
- (...fns: AnyFunc[]) =>
49
- (s: any = __) => {
47
+ type Composed<TIn, TOut> = (x: TIn) => TOut
48
+ export const compose = (
49
+ <TIn = any, TOut = any>(...fns: AnyFunc[]): Composed<TIn, TOut> =>
50
+ (s: TIn = Symbol() as any) => {
50
51
  for(let i = length(fns)-1; i>-1; i--) {
51
52
  s = s===__ ? fns[i]() : fns[i](s)
52
53
  }
53
- return s
54
+ return s as any as TOut
54
55
  }
55
56
  )
56
57
 
@@ -58,11 +59,11 @@ export const bind = curry2<AnyFunc>(
58
59
  (fn: AnyFunc, context: any) => fn.bind(context)
59
60
  )
60
61
 
61
- const _nth = <T=any>(i: number, data: T[]) => data[i]
62
+ const _nth = <T=any>(i: number, data: T[] | string) => data[i]
62
63
  export const nth = curry2(_nth)
63
64
 
64
65
  export const includes = curry2(
65
- (s: any, ss: any[]) => {
66
+ <T>(s: T, ss: T[]) => {
66
67
  if(isStr(ss)) {
67
68
  return ss.includes(s)
68
69
  } else {
@@ -76,11 +77,11 @@ export const includes = curry2(
76
77
  }
77
78
  )
78
79
  export const slice = curry3(
79
- (from: number, to: number|null, o: any[] | string) =>
80
- o.slice(from, (isNum(to)?to:Infinity) as number)
80
+ (from: number, to: number, o: any[] | string) =>
81
+ o.slice(from, (isNum(to)?to:inf) as number)
81
82
  )
82
83
  export const head = nth(0)
83
- export const tail = slice(1, nul)
84
+ export const tail = slice(1, inf) // typeshit.
84
85
  export const add = curry2((n: number, m: number) => n+m)
85
86
  export const subtract = curry2((n: number, m: number) => m-n)
86
87
  export const flip = (fn: Function) => curry((b: any, a: any) => fn(a, b))
@@ -115,7 +116,7 @@ export const range = curry2((from: number, to: number) =>
115
116
  genBy(add(from), to-from)
116
117
  )
117
118
  export const uniq = (xs: any[]) => qreduce(
118
- (accum: any[], x: any) =>
119
+ <T>(accum: any, x: T) =>
119
120
  includes(x, accum) ? accum : qappend(x, accum),
120
121
  [], xs)
121
122
  export const intersection = curry2(
@@ -139,8 +140,8 @@ export const once = <Func extends AnyFunc>(fn: Func) => {
139
140
  }
140
141
  }
141
142
  export const reverse = (xs: any[]) => compose(
142
- (ln: number) => reduce(
143
- (nxs: any[], _: any, i: number) => qappend(xs[ln-i], nxs),
143
+ <T>(ln: number) => reduce<any>(
144
+ (nxs: T[], _: any, i: number) => qappend(xs[ln-i], nxs),
144
145
  [], xs
145
146
  ),
146
147
  add(-1),
@@ -178,7 +179,7 @@ export const assocPath = curry3(
178
179
  first,
179
180
  length(_path)<2
180
181
  ? v
181
- : assocPath(slice(1, null, _path), v, isObj(o[first]) ? o[first] : {}),
182
+ : assocPath(slice(1, inf, _path), v, isObj(o[first]) ? o[first] : {}),
182
183
  o
183
184
  ),
184
185
  head
@@ -207,7 +208,7 @@ export const pathOr = curry3(
207
208
  : compose(
208
209
  ifElse(isNil,
209
210
  always(_default),
210
- (o: any) => pathOr(_default, slice(1, nul, path), o)
211
+ (o: any) => pathOr(_default, slice(1, inf, path), o)
211
212
  ),
212
213
  flip(prop)(o),
213
214
  head
@@ -269,7 +270,7 @@ export const omit = curry2(
269
270
  o
270
271
  )
271
272
  )
272
- export const fromPairs = (pairs: [string, any][]) => reduce(
273
+ export const fromPairs = (pairs: [string, any][]) => reduce<any>(
273
274
  (o: AnyObject, pair: [string, any]) => assoc(...pair, o),
274
275
  {}, pairs
275
276
  )
package/src/types.ts CHANGED
@@ -7,7 +7,7 @@ export type Curried<
7
7
  Args extends AnyArgs = AnyArgs,
8
8
  ReturnT = any
9
9
  > = (arg: Args[number]) => Curried<Args> | ReturnT
10
- export type Reducer = <T>(accum: T, cur: any, index: number) => T
10
+ export type Reducer = <T=any>(accum: T, cur: any, index: number) => T
11
11
  export type AnyFunc<
12
12
  ReturnT = any,
13
13
  Args extends AnyArgs = AnyArgs
package/src/uncurry.ts CHANGED
@@ -6,6 +6,6 @@ export const uncurry = <
6
6
  Args extends any[] = any[],
7
7
  ReturnT = any
8
8
  >(fn: Curried<Args>): AnyFunc =>
9
- (...args: Args) => qreduce(
9
+ (...args: Args) => qreduce<any>(
10
10
  ((fn: Curried<Args>, arg: any) => fn ? fn(arg) : fn), fn, args
11
11
  ) as ReturnT