UNPKG

@mojir/lits

Version:

Lits is a pure functional programming language implemented in TypeScript

3 lines (2 loc) 25.3 kB
function e(e){if(!e.position||!e.code)return"";const t=e.position.column-1,n=e.code.length-t-1;return`${" ".repeat(Math.max(t,0))}^${" ".repeat(Math.max(n,0))}`}class t extends Error{sourceCodeInfo;shortMessage;constructor(n,o){const r=n instanceof Error?n.message:`${n}`;super(function(t,n){if(!n)return t;const o=`${n.position.line}:${n.position.column}`;return`${t}${n.filePath?`\n${n.filePath}:${o}`:`\nLocation ${o}`}\n${n.code}\n${e(n)}`}(r,o)),this.shortMessage=r,this.sourceCodeInfo=o,Object.setPrototypeOf(this,t.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&e(this.sourceCodeInfo)}}const n={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},o=new Set(Object.values(n));const r=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const i="^^fn^^",c="^^re^^";function l(e){return null!==e&&"object"==typeof e&&(i in e&&"functionType"in e&&("string"==typeof(t=e.functionType)&&r.has(t)));var t}function a(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(t=e[0])&&o.has(t));var t}function u(e){return l(e)?`<function ${e.name||"λ"}>`:a(e)?`${t=e[0],Object.keys(n).find(e=>n[e]===t)}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e);var t}function s(e,t){return e?.sourceCodeInfo??t}function p(e,n,o){return new t(`Expected ${e}, got ${u(n)}.`,s(n,o))}function y(e){return null!==e&&"object"==typeof e&&!!e[i]}function m(e,t){if(!function(e){return void 0!==e}(e))throw p("not undefined",e,t)}function f(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||y(e)||(t=e,null!==t&&"object"==typeof t&&t[c]));var t}function h(e){return function(e){return Array.isArray(e)||"string"==typeof e}(e)||f(e)}function g(e,t){return d(e,t),e}function d(e,t){if(!h(e))throw p("string, array or object",e,t)}function b(e,t){if(!function(e){return"number"==typeof e||!!h(e)||!!y(e)}(e))throw p("FunctionLike",e,t)}function v(e,t={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(t.integer&&!Number.isInteger(e))&&(!(t.finite&&!Number.isFinite(e))&&((!t.zero||0===e)&&((!t.nonZero||0!==e)&&(!(t.positive&&e<=0)&&(!(t.negative&&e>=0)&&(!(t.nonPositive&&e>0)&&(!(t.nonNegative&&e<0)&&(!("number"==typeof t.gt&&e<=t.gt)&&(!("number"==typeof t.gte&&e<t.gte)&&(!("number"==typeof t.lt&&e>=t.lt)&&!("number"==typeof t.lte&&e>t.lte)))))))))))))}function x(e,n,o={}){if(!v(e,o))throw new t(`Expected ${function(e){if(e.zero)return"zero";const t=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),n=e.integer?"integer":"number",o=e.finite?"finite":"",r=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[t,o,n,r].filter(e=>!!e).join(" ")}(o)}, got ${u(e)}.`,s(e,n))}function $(e,t,n={}){if(!function(e,t={}){return!("string"!=typeof e||t.nonEmpty&&0===e.length||t.char&&1!==e.length)}(e,n))throw p(""+(n.nonEmpty?"non empty string":n.char?"character":"string"),e,t)}function A(e,t){return w(e,t),e}function w(e,t){if(!function(e){return"string"==typeof e||"number"==typeof e}(e))throw p("string or number",e,t)}function j(e,t){return!!h(e)&&("string"==typeof e||Array.isArray(e)?!!v(t,{integer:!0})&&(t>=0&&t<e.length):!!Object.getOwnPropertyDescriptor(e,t))}function k(e){return e??null}function N(e){return f(e)?Object.entries(e).reduce((e,t)=>{const[n,o]=t;return e[n]=N(o),e},{}):Array.isArray(e)?e.map(e=>N(e)):e}function O(e){return N(e)}function T(e,t){if(!Array.isArray(e))throw p("array",e,t)}function F(e){return{min:e,max:e}}function C(e,t){return e instanceof Promise?e.then(t):t(e)}function M(e,t){const n=[];for(let o=0;o<e.length;o++){const r=t(e[o],o);if(r instanceof Promise)return P(r,n,e,t,o);n.push(r)}return n}async function P(e,t,n,o,r){t.push(await e);for(let e=r+1;e<n.length;e++)t.push(await o(n[e],e));return t}function R(e,t,n){let o=n;for(let n=0;n<e.length;n++){const r=t(o,e[n],n);if(r instanceof Promise)return S(r,e,t,n);o=r}return o}async function S(e,t,n,o){let r=await e;for(let e=o+1;e<t.length;e++)r=await n(r,t[e],e);return r}function E(e,t){for(let n=0;n<e.length;n++){const o=t(e[n],n);if(o instanceof Promise)return I(o,e,t,n);if(o)return!0}return!1}async function I(e,t,n,o){if(await e)return!0;for(let e=o+1;e<t.length;e++)if(await n(t[e],e))return!0;return!1}function B(e,t){for(let n=0;n<e.length;n++){const o=t(e[n],n);if(o instanceof Promise)return z(o,e,t,n);if(!o)return!1}return!0}async function z(e,t,n,o){if(!await e)return!1;for(let e=o+1;e<t.length;e++)if(!await n(t[e],e))return!1;return!0}function L(e,t){const n=[];for(let o=0;o<e.length;o++){const r=t(e[o],o);if(r instanceof Promise)return U(r,n,e,t,o);r&&n.push(e[o])}return n}async function U(e,t,n,o,r){await e&&t.push(n[r]);for(let e=r+1;e<n.length;e++)await o(n[e],e)&&t.push(n[e]);return t}function D(e,t){if(f(e)){if("string"==typeof t&&j(e,t))return k(e[t])}else if(v(t,{nonNegative:!0,integer:!0})&&t>=0&&t<e.length)return k(e[t])}function J(e,t,n,o){if(d(e,o),Array.isArray(e)||"string"==typeof e){if(x(t,o,{integer:!0}),x(t,o,{gte:0}),x(t,o,{lte:e.length}),"string"==typeof e)return $(n,o,{char:!0}),`${e.slice(0,t)}${n}${e.slice(t+1)}`;const r=[...e];return r[t]=n,r}$(t,o);const r={...e};return r[t]=n,r}function K(e,t,n,o,r,i,c){if(f(e)){$(t,c);const l={...e};return C(i(n,[l[t],...o],r,c),e=>(l[t]=e,l))}{x(t,c);const a=(l=t,Math.max(0,Math.ceil(l)));if(x(a,c,{lte:e.length}),Array.isArray(e))return C(M(Array.from({length:e.length+(a===e.length?1:0)}),(t,l)=>a===l?i(n,[e[l],...o],r,c):e[l]),e=>e);{const t=e.split("");return C(M(Array.from({length:t.length+(a===t.length?1:0)}),(e,l)=>a===l?C(i(n,[t[l],...o],r,c),e=>function(e,t,n={}){return $(e,t,n),e}(e,c,{char:!0})):t[l]),e=>e.join(""))}}var l}function Z(e,t,n){const o=O(e);return{coll:o,innerCollMeta:t.slice(0,t.length-1).reduce((e,t)=>{const o=e.coll;let r;return Array.isArray(o)?(x(t,n),r=g(o[t],n)):(!function(e,t){if(!f(e))throw p("object",e,t)}(o,n),$(t,n),j(e.coll,t)||(o[t]={}),r=g(o[t],n)),{coll:r,parent:o}},{coll:o,parent:{}})}}const q={name:"collection",functions:{"get-in":{evaluate:(e,t)=>{let n=k(e[0]);const o=e[1]??[],r=k(e[2]);T(o,t);for(const e of o){if(w(e,t),!h(n))return r;{const t=D(n,e);if(void 0===t)return r;n=t}}return n},arity:{min:2,max:3},docs:{category:"collection",returns:{type:"any"},args:{a:{type:"collection"},b:{type:"array"},"not-found":{type:"any"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","not-found"]}],description:"Returns the value in a nested collection, where $b is an array of keys. Returns $not-found if the key is not present. If $not-found is not set, `null` is returned.",seeAlso:["get","collection.assoc-in","collection.update-in"],examples:['\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "a", 0]\n)','\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "b", 0]\n)','\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "b", 0],\n "Lisa"\n)']}},"assoc-in":{evaluate:([e,t,n],o)=>{if(d(e,o),T(t,o),m(n,o),1===t.length)return w(t[0],o),J(e,t[0],n,o);const{coll:r,innerCollMeta:i}=Z(e,t,o),c=A(t[t.length-1],o),l=A(t[t.length-2],o);return Array.isArray(i.parent)?(x(l,o),i.parent[l]=J(i.coll,c,n,o)):($(l,o),i.parent[l]=J(i.coll,c,n,o)),r},arity:F(3),docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},ks:{type:["number","string"],array:!0},value:{type:"any"}},variants:[{argumentNames:["coll","ks","value"]}],description:"\nAssociates a value in the nested collection $coll, where $ks is an array of keys and $value is the new value.\n\nIf any levels do not exist, objects will be created - and the corresponding keys must be of type string.",seeAlso:["assoc","collection.get-in","collection.update-in"],examples:['\nlet cu = import(collection);\ncu.assoc-in(\n {},\n ["a", "b", "c"],\n "Albert"\n)','\nlet cu = import(collection);\ncu.assoc-in(\n [1, 2, [1, 2, 3]],\n [2, 1],\n "Albert"\n)','\nlet cu = import(collection);\ncu.assoc-in(\n [1, 2, { name: "albert" }],\n [2, "name", 0],\n "A"\n)']}},update:{evaluate:([e,t,n,...o],r,i,{executeFunction:c})=>(d(e,r),w(t,r),b(n,r),K(e,t,n,o,i,c,r)),arity:{min:3},docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},key:{type:["string","number"]},fun:{type:"function"},"fun-args":{type:"any",rest:!0}},variants:[{argumentNames:["coll","value","fun"]},{argumentNames:["coll","value","fun","fun-args"]}],description:"\nUpdates a value in the $coll collection, where $key is a key. $fun is a function\nthat will take the old value and any supplied $fun-args and\nreturn the new value.\nIf the key does not exist, `null` is passed as the old value.",seeAlso:["collection.update-in","assoc"],examples:['\nlet cu = import(collection);\nlet x = { a: 1, b: 2 };\ncu.update(x, "a", inc)','\nlet cu = import(collection);\nlet x = { a: 1, b: 2 };\ncu.update(\n x,\n "c",\n val -> null?(val) ? 0 : inc(val)\n)']}},"update-in":{evaluate:([e,t,n,...o],r,i,{executeFunction:c})=>{if(d(e,r),T(t,r),b(n,r),1===t.length)return w(t[0],r),K(e,t[0],n,o,i,c,r);const{coll:l,innerCollMeta:a}=Z(e,t,r),u=A(t[t.length-1],r),s=A(t[t.length-2],r);return Array.isArray(a.parent)?(x(s,r),C(K(a.coll,u,n,o,i,c,r),e=>(a.parent[s]=e,l))):($(s,r),C(K(a.coll,u,n,o,i,c,r),e=>(a.parent[s]=e,l)))},arity:{min:3},docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},ks:{type:"array"},fun:{type:"function"},"fun-args":{type:"any",rest:!0}},variants:[{argumentNames:["coll","ks","fun"]},{argumentNames:["coll","ks","fun","fun-args"]}],description:"Updates a value in the $coll collection, where $ks is an array of\nkeys and $fun is a function that will take the old value and\nany supplied $fun-args and return the new value. If any levels do not exist,\nobjects will be created - and the corresponding keys must be of type string.",seeAlso:["collection.update","collection.assoc-in","collection.get-in"],examples:['\nlet cu = import(collection);\ncu.update-in(\n { a: [1, 2, 3] },\n ["a", 1],\n -> null?($) ? 0 : inc($)\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: { foo: "bar"} },\n ["a", "foo"],\n -> null?($) ? "?" : "!"\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: { foo: "bar"} },\n ["a", "baz"],\n -> null?($) ? "?" : "!"\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: [1, 2, 3] },\n ["a", 1],\n *,\n 10,\n 10,\n 10,\n)']}},filteri:{evaluate:([e,t],n,o,{executeFunction:r})=>(d(e,n),b(t,n),Array.isArray(e)?L(e,(e,i)=>r(t,[e,i],o,n)):"string"==typeof e?C(L(e.split(""),(e,i)=>r(t,[e,i],o,n)),e=>e.join("")):C(L(Object.entries(e),([e,i])=>r(t,[i,e],o,n)),e=>e.reduce((e,[t,n])=>(e[t]=n,e),{}))),arity:F(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function",description:"The function to call for each element in the collection. The function should take two arguments: the element itself and the index."}},variants:[{argumentNames:["a","b"]}],description:"Creates a new collection with all elements that pass the test implemented by $b. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.",seeAlso:["filter","collection.mapi"],examples:["let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> i % 2 == 0)","let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> x % 2 == 0)","let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> x + i > 3)"]}},mapi:{evaluate:([e,t],n,o,{executeFunction:r})=>{if(d(e,n),b(t,n),Array.isArray(e))return M(e,(e,i)=>r(t,[e,i],o,n));if("string"==typeof e)return C(M(e.split(""),(e,i)=>r(t,[e,i],o,n)),e=>e.join(""));return R(Object.entries(e),(e,[i,c])=>C(r(t,[c,i],o,n),t=>(e[i]=t,e)),{})},arity:F(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function",description:"The function to call for each element in the collection. The function should take two arguments: the element itself and the index."}},variants:[{argumentNames:["a","b"]}],description:"Creates a new collection populated with the results of calling $b on every element in $a. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.",seeAlso:["map","collection.filteri"],examples:["let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x + i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x * i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x - i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x / i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x % inc(i))"]}},reducei:{evaluate:([e,t,n],o,r,{executeFunction:i})=>(d(e,o),b(t,o),m(n,o),"string"==typeof e?($(n,o),0===e.length?n:R(e.split("").map((e,t)=>({elem:e,index:t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n)):Array.isArray(e)?0===e.length?n:R(e.map((e,t)=>({elem:e,index:t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n):0===Object.keys(e).length?n:R(Object.entries(e),(e,[n,c])=>i(t,[e,c,n],r,o),n)),arity:F(3),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["reduce","collection.reducei-right","collection.reductionsi"],examples:["let cu = import(collection); cu.reducei([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reducei("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reducei({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},"reduce-right":{evaluate:([e,t,n],o,r,{executeFunction:i})=>(d(e,o),b(t,o),m(n,o),"string"==typeof e?0===e.length?n:R(Array.from(e.split("")).reverse(),(e,n)=>i(t,[e,n],r,o),n):Array.isArray(e)?0===e.length?n:R(Array.from(e).reverse(),(e,n)=>i(t,[e,n],r,o),n):0===Object.keys(e).length?n:R(Object.entries(e).reverse(),(e,[,n])=>i(t,[e,n],r,o),n)),arity:F(3),docs:{category:"collection",returns:{type:"any"},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value.",seeAlso:["reduce","collection.reducei-right"],examples:['let cu = import(collection); cu.reduce-right(["A", "B", "C"], str, "")',"let cu = import(collection); cu.reduce-right({ a: 1, b: 2 }, +, 0)"]}},"reducei-right":{evaluate:([e,t,n],o,r,{executeFunction:i})=>(d(e,o),b(t,o),m(n,o),"string"==typeof e?0===e.length?n:R(Array.from(e.split("")).reverse().map((e,t,n)=>({elem:e,index:n.length-1-t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n):Array.isArray(e)?0===e.length?n:R(Array.from(e).reverse().map((e,t,n)=>({elem:e,index:n.length-1-t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n):0===Object.keys(e).length?n:R(Object.entries(e).reverse(),(e,[n,c])=>i(t,[e,c,n],r,o),n)),arity:F(3),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["collection.reducei","collection.reduce-right"],examples:["let cu = import(collection); cu.reducei-right([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reducei-right("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reducei-right({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},reductions:{evaluate:([e,t,n],o,r,{executeFunction:i})=>{d(e,o),b(t,o),m(n,o),m(n,o);const c="string"==typeof e?($(n,o),0===e.length?[]:e.split("")):Array.isArray(e)?0===e.length?[]:Array.from(e):0===Object.keys(e).length?[]:Object.entries(e).map(([,e])=>e);if(0===c.length)return[n];const l=[n];return C(R(c,(e,n)=>C(i(t,[e,n],r,o),e=>(l.push(e),e)),n),()=>l)},arity:F(3),docs:{category:"collection",returns:{type:"any",array:!0},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun.",seeAlso:["reduce","collection.reductionsi"],examples:["let cu = import(collection); cu.reductions([1, 2, 3], +, 0)","let cu = import(collection); cu.reductions([1, 2, 3], +, 10)","let cu = import(collection); cu.reductions([], +, 0)","let cu = import(collection); cu.reductions({ a: 1, b: 2 }, +, 0)","\nlet cu = import(collection);\ncu.reductions(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + (even?(value) ? value : 0),\n 0\n)"]}},reductionsi:{evaluate:([e,t,n],o,r,{executeFunction:i})=>{d(e,o),b(t,o),m(n,o),m(n,o);const c=(e,t)=>({elem:e,key:t}),l="string"==typeof e?($(n,o),0===e.length?[]:e.split("").map((e,t)=>c(e,t))):Array.isArray(e)?0===e.length?[]:e.map((e,t)=>c(e,t)):0===Object.keys(e).length?[]:Object.entries(e).map(([e,t])=>c(t,e));if(0===l.length)return[n];const a=[n];return C(R(l,(e,{elem:n,key:c})=>C(i(t,[e,n,c],r,o),e=>(a.push(e),e)),n),()=>a)},arity:F(3),docs:{category:"collection",returns:{type:"any",array:!0},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["collection.reductions","collection.reducei"],examples:["let cu = import(collection); cu.reductionsi([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reductionsi("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reductionsi({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},"not-empty":{evaluate:([e],t)=>null===e?null:(d(e,t),"string"==typeof e||Array.isArray(e)?e.length>0?e:null:Object.keys(e).length>0?e:null),arity:F(1),docs:{category:"collection",returns:{type:"boolean"},args:{coll:{type:["collection","null"]}},variants:[{argumentNames:["coll"]}],description:"Returns `null` if $coll is empty or `null`, otherwise $coll.",seeAlso:["empty?","not-empty?"],examples:["let cu = import(collection); cu.not-empty([])","let cu = import(collection); cu.not-empty([1, 2, 3])","let cu = import(collection); cu.not-empty({})","let cu = import(collection); cu.not-empty({ a: 2 })",'let cu = import(collection); cu.not-empty("")','let cu = import(collection); cu.not-empty("Albert")',"let cu = import(collection); cu.not-empty(null)"]}},"every?":{evaluate:([e,t],n,o,{executeFunction:r})=>{d(e,n),b(t,n);return B(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n))},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if all entries in $a pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.any?","collection.not-every?","collection.not-any?","functional.every-pred","grid.cell-every?"],examples:["let cu = import(collection); cu.every?([1, 2, 3], number?)","let cu = import(collection); cu.every?([1, 2, 3], even?)",'\nlet cu = import(collection);\ncu.every?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?,\n)',"\nlet cu = import(collection);\ncu.every?(\n [50, 100, 150, 200],\n -> $ > 10,\n)","let cu = import(collection); cu.every?([], number?)",'let cu = import(collection); cu.every?("", number?)',"let cu = import(collection); cu.every?({}, number?)","\nlet cu = import(collection);\ncu.every?(\n { a: 2, b: 4},\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.every?(\n { a: 2, b: 3 },\n -> even?(second($))\n)"]}},"any?":{evaluate:([e,t],n,o,{executeFunction:r})=>{b(t,n),d(e,n);return E(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n))},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if any element in $a pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.every?","collection.not-any?","collection.not-every?","functional.some-pred","some","grid.some?"],examples:['\nlet cu = import(collection);\ncu.any?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.any?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.any?([], number?)",'let cu = import(collection); cu.any?("", number?)',"let cu = import(collection); cu.any?({}, number?)","\nlet cu = import(collection);\ncu.any?(\n { a: 2, b: 3 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.any?(\n { a: 1, b: 3 },\n -> even?(second($))\n)"]}},"not-any?":{evaluate:([e,t],n,o,{executeFunction:r})=>{b(t,n),d(e,n);return C(E(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n)),e=>!e)},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `false` if any element in $a pass the test implemented by $b, otherwise returns `true`.",seeAlso:["collection.any?","collection.every?","collection.not-every?"],examples:['\nlet cu = import(collection);\ncu.not-any?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.not-any?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.not-any?([], number?)",'let cu = import(collection); cu.not-any?("", number?)',"let cu = import(collection); cu.not-any?({}, number?)","\nlet cu = import(collection);\ncu.not-any?(\n { a: 2, b: 3 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.not-any?(\n { a: 1, b: 3 },\n -> even?(second($))\n)"]}},"not-every?":{evaluate:([e,t],n,o,{executeFunction:r})=>{b(t,n),d(e,n);return C(B(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n)),e=>!e)},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if at least one element in $a does not pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.every?","collection.any?","collection.not-any?"],examples:['\nlet cu = import(collection);\ncu.not-every?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.not-every?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.not-every?([], number?)",'let cu = import(collection); cu.not-every?("", number?)',"let cu = import(collection); cu.not-every?({}, number?)","\nlet cu = import(collection);\ncu.not-every?(\n { a: 2, b: 4 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.not-every?(\n { a: 2, b: 3 },\n -> even?(second($))\n)"]}}}};export{q as collectionUtilsModule}; //# sourceMappingURL=collection.esm.js.map