UNPKG

fun-unfold

Version:

Unfold a complex value from a generator, predicate, and seed

2 lines (1 loc) 3.69 kB
!function n(r,t,o){function e(i,f){if(!t[i]){if(!r[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var s=new Error("Cannot find module '"+i+"'");throw s.code="MODULE_NOT_FOUND",s}var a=t[i]={exports:{}};r[i][0].call(a.exports,function(n){var t=r[i][1][n];return e(t?t:n)},a,a.exports,n,r,t,o)}return t[i].exports}for(var u="function"==typeof require&&require,i=0;i<o.length;i++)e(o[i]);e}({1:[function(n,r,t){funUnfold=n("..")},{"..":5}],2:[function(n,r,t){(()=>{"use strict";const t=n("stringify-anything"),o=(n,r,t)=>Object.defineProperty(t,n,{value:r}),e=(n,r)=>o("name",n,r),u=(n,r)=>o("length",n,r),i=n=>{throw Error(n)},f=(n,r,o)=>{"function"!=typeof n&&i(`${t(n)} should be a function`),"number"!=typeof r&&i(`${t(r)} should be a number`),o instanceof Array||i(`${t(o)} should be an Array`)},c=(n,r)=>t(n)+(r.length?`(${r.map(t).join(",")})`:""),s=(n,r=n.length,t=[])=>{return f(n,r,t),e(c(n,t),u(r,(...o)=>{const e=t.concat(o.length?o:[void 0]);return e.length>=r?n.apply(null,e):u(r-e.length,s(n,r,e))}))};r.exports=s})()},{"stringify-anything":4}],3:[function(n,r,t){(()=>{"use strict";const t=n("stringify-anything"),o=n("fun-curry"),e=n=>0===n.length,u=n=>"number"==typeof n,i=n=>"function"==typeof n,f=(n,r)=>Object.keys(r).reduce((t,o)=>{return t[o]=n(r[o]),t},{}),c=n=>`\`${t(n)}\``,s=n=>{throw n},a="A contract with a guarded function has been broken!\n",p=(n,r,t)=>n(r)?r:s(t),y=(n,r,t)=>Object.defineProperty(t,n,Object.defineProperty(Object.getOwnPropertyDescriptor(t,n),"value",{value:r})),g=(n,r)=>y("length",n.length,y("name",n.name,r)),l=(n,r,...t)=>{return p(i,n,Error(a+`${c(n)} should be a function`)),p(i,r,Error(a+`${c(r)} should be a function`)),p(e,t,Error(a+`Extra arguments passed to io: ${c(t)}`)),g(r,(...t)=>{const e=r(...t);return p(o(n)(t),e,Error(a+`(inputs -> output) pair (${c(t)} ->`+` ${c(e)}) from function ${c(r)}`+` failed predicate ${c(n)}`)),e})},E=(n,r,...t)=>{return p(i,n,Error(a+`${c(n)} should be a function`)),p(i,r,Error(a+`${c(r)} should be a function`)),p(e,t,Error(a+`Extra arguments passed to inputs: ${c(t)}`)),g(r,(...t)=>{return p(n,t,Error(a+`inputs ${c(t)} to function ${c(r)}`+` failed predicate ${c(n)}`)),r(...t)})},h=(n,r,t,...o)=>{return p(u,n,Error(a+`${c(n)} should be a number`)),p(i,r,Error(a+`${c(r)} should be a function`)),p(i,t,Error(a+`${c(t)} should be a function`)),p(e,o,Error(a+`Extra arguments passed to inputN: ${c(o)}`)),g(t,(...o)=>{return p(r,o[n],Error(a+`input ${n} ${c(o[n])} to function`+` ${c(t)} failed predicate ${c(r)}`)),t(...o)})},d=(n,r,...t)=>h(0,n,r,...t),b=(n,r,...t)=>{return p(i,n,Error(a+`${c(n)} should be a function`)),p(i,r,Error(a+`${c(r)} should be a function`)),p(e,t,Error(a+`Extra arguments passed to output: ${c(t)}`)),g(r,(...t)=>{const o=r(...t);return p(n,o,Error(a+`output ${c(o)} of function ${c(r)}`+` with arguments ${c(t)} failed predicate ${c(n)}`)),o})},O={io:l,inputs:E,inputN:h,input:d,output:b};r.exports=f(o,O)})()},{"fun-curry":2,"stringify-anything":4}],4:[function(n,r,t){(()=>{"use strict";const n=n=>null===n||"boolean"==typeof n||"number"==typeof n||"string"==typeof n,t=r=>n(r)?JSON.stringify(r):void 0===r?"undefined":r instanceof Function?r.name||"=>":r instanceof RegExp||r instanceof Error?r.toString():r instanceof Array?`[${r.map(t).join(",")}]`:`{${Object.keys(r).join(",")}}`;r.exports=t})()},{}],5:[function(n,r,t){(()=>{"use strict";const{inputs:inputs}=n("guarded"),t=n("fun-curry"),o=(n,r,t)=>{for(;!r(t);)t=n(t);return t},e=(n,r)=>n.length===r.length&&n.reduce((n,t,o)=>n&&t(r[o]),!0),u=n=>"function"==typeof n,i=()=>!0;r.exports=t(inputs(t(e)([u,u,i]),o))})()},{"fun-curry":2,guarded:3}]},{},[1]);