UNPKG

@mojir/lits

Version:

Lits is a pure functional programming language implemented in TypeScript

3 lines (2 loc) 24.4 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,s){const r=n instanceof Error?n.message:`${n}`;super(function(t,n){if(!n)return t;const s=`${n.position.line}:${n.position.column}`;return`${t}${n.filePath?`\n${n.filePath}:${s}`:`\nLocation ${s}`}\n${n.code}\n${e(n)}`}(r,s)),this.shortMessage=r,this.sourceCodeInfo=s,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},s=new Set(Object.values(n));const r=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const u="^^fn^^";function i(e){return null!==e&&"object"==typeof e&&(u in e&&"functionType"in e&&("string"==typeof(t=e.functionType)&&r.has(t)));var t}function o(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(t=e[0])&&s.has(t));var t}function a(e){return i(e)?`<function ${e.name||"λ"}>`:o(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 c(e,t){return e?.sourceCodeInfo??t}function p(e,n,s){return new t(`Expected ${e}, got ${a(n)}.`,c(n,s))}function l(e,t){if(!Array.isArray(e))throw p("array",e,t)}function m(e,t){if(!function(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e&&1===e.length)}(e))throw p("array of strings",e,t)}function f(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function y(e){return null!==e&&"object"==typeof e&&!!e[u]}function q(e,t){return g(e,t),e}function g(e,t){if(!function(e){return void 0!==e}(e))throw p("not undefined",e,t)}function h(e){return Array.isArray(e)||"string"==typeof e}function d(e,t){return b(e,t),e}function b(e,t){if(!h(e))throw p("string or array",e,t)}function v(e){return h(e)||function(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||y(e)||$(e))}(e)}function $(e){return null!==e&&"object"==typeof e&&!!e["^^re^^"]}function A(e,t){if(!function(e){return"number"==typeof e||!!v(e)||!!y(e)}(e))throw p("FunctionLike",e,t)}function w(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,s={}){if(!w(e,s))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",s=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,s,n,r].filter(e=>!!e).join(" ")}(s)}, got ${a(e)}.`,c(e,n))}function j(e,t,n={}){return x(e,t,n),e}function N(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 M(e,t,n={}){return N(e,t,n),e}function k(e,t){if(!function(e){return"string"==typeof e||"number"==typeof e}(e))throw p("string or number",e,t)}function R(e,t){return!!v(e)&&("string"==typeof e||Array.isArray(e)?!!w(t,{integer:!0})&&(t>=0&&t<e.length):!!Object.getOwnPropertyDescriptor(e,t))}function I(e,t,n){if(e===t)return!0;if("number"==typeof e&&"number"==typeof t)return function(e,t,n=P){if(e===t)return!0;const s=Math.abs(e-t);if(0===e||0===t||s<n)return s<n;const r=Math.abs(e),u=Math.abs(t);return s/(r+u)<n}(e,t);if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let s=0;s<e.length;s+=1)if(!I(q(e[s],n),q(t[s],n),n))return!1;return!0}if($(e)&&$(t))return e.s===t.s&&e.f===t.f;if(f(e)&&f(t)){const s=Object.keys(e),r=Object.keys(t);if(s.length!==r.length)return!1;for(let r=0;r<s.length;r+=1){const u=M(s[r],n);if(!I(e[u],t[u],n))return!1}return!0}return!1}function E(e){return Math.max(0,Math.ceil(e))}const P=1e-10;function S(e){return{min:e,max:e}}function C(e,t){return e instanceof Promise?e.then(t):t(e)}async function O(e,t,n,s,r){t.push(await e);for(let e=r+1;e<n.length;e++)t.push(await s(n[e],e));return t}function F(e,t,n){let s=n;for(let n=0;n<e.length;n++){const r=t(s,e[n],n);if(r instanceof Promise)return z(r,e,t,n);s=r}return s}async function z(e,t,n,s){let r=await e;for(let e=s+1;e<t.length;e++)r=await n(r,t[e],e);return r}async function B(e,t,n,s,r){await e&&t.push(n[r]);for(let e=r+1;e<n.length;e++)await s(n[e],e)&&t.push(n[e]);return t}function L(e,t){for(let n=0;n<e.length;n++){const s=t(e[n],n);if(s instanceof Promise)return T(s,e,t,n);if(s)return n}return-1}async function T(e,t,n,s){if(await e)return s;for(let e=s+1;e<t.length;e++)if(await n(t[e],e))return e;return-1}const U={position:{evaluate:([e,t],n,s,{executeFunction:r})=>{if(A(t,n),null===e)return null;b(e,n);return C(L("string"==typeof e?e.split(""):e,e=>r(t,[e],s,n)),e=>-1!==e?e:null)},arity:S(2),docs:{category:"sequence",returns:{type:["number","null"]},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:["sequence","null"]},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns the index of the first elements that passes the test implemented by $fun. If no element was found, `null` is returned.",seeAlso:["index-of","some","find"],examples:['\nlet su = import(sequence);\nsu.position(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet su = import(sequence);\nsu.position(\n [5, 10, 15, 20],\n -> $ > 10\n)","\nlet su = import(sequence);\nsu.position(\n [5, 10, 15, 20],\n -> $ > 100\n)","\nlet su = import(sequence);\nsu.position(\n null,\n -> $ > 100\n)"]}},"last-index-of":{evaluate:([e,t],n)=>{if(g(t,n),null===e)return null;if(b(e,n),"string"==typeof e){N(t,n);const s=e.lastIndexOf(t);return-1!==s?s:null}{const s=e.findLastIndex(e=>I(q(e,n),t),n);return-1!==s?s:null}},arity:S(2),docs:{category:"sequence",returns:{type:["number","null"]},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:["sequence","null"]},x:{type:"any"}},variants:[{argumentNames:["seq","x"]}],description:"Returns the last index of $x in $seq. If element is not present in $seq `null` is returned.",seeAlso:["index-of"],examples:["let su = import(sequence); su.last-index-of([[1], [2], [1], [2]], [1])",'let su = import(sequence); su.last-index-of(["Albert", "Mojir", 160, [1, 2]], "Mojir")',"let su = import(sequence); su.last-index-of([5, 10, 15, 20, 15], 15)","let su = import(sequence); su.last-index-of([5, 10, 15, 20], 1)","let su = import(sequence); su.last-index-of(null, 1)"]}},splice:{evaluate:(e,t)=>{const[n,s,r,...u]=e;b(n,t),x(s,t,{integer:!0}),x(r,t,{integer:!0,nonNegative:!0});const i=s<0?n.length+s:s;return Array.isArray(n)?[...n.slice(0,i),...u,...n.slice(i+r)]:(u.forEach(e=>N(e,t)),`${n.substring(0,i)}${u.join("")}${n.substring(i+r)}`)},arity:{min:3},docs:{category:"sequence",returns:{type:"sequence"},args:{seq:{type:"sequence",rest:!0},start:{type:"integer"},deleteCount:{type:"integer"},items:{type:"any",rest:!0}},variants:[{argumentNames:["seq","start","deleteCount"]},{argumentNames:["seq","start","deleteCount","items"]}],description:"Returns a a spliced array. Removes $deleteCount elements from $seq starting at $start and replaces them with $items. If $start is negative, it is counting from the end of the array.",seeAlso:["slice","sequence.remove-at"],examples:['let su = import(sequence); su.splice([1, 2, 3, 4, 5], 2, 2, "x")','let su = import(sequence); su.splice([1, 2, 3, 4, 5], -2, 1, "x")','let su = import(sequence); su.splice("Albert", 2, 2, "fo")']}},"sort-by":{evaluate:(e,n,s,{executeFunction:r})=>{const[u,i]=e,o=2===e.length;b(u,n),A(i,n);const a=o?null:e[2],c="string"==typeof u,p=c?u.split(""):[...u];return C(function(e,t){const n=[];for(let s=0;s<e.length;s++){const r=t(e[s],s);if(r instanceof Promise)return O(r,n,e,t,s);n.push(r)}return n}(p,e=>r(i,[e],s,n)),e=>{if(o){const s=p.map((t,n)=>({elem:t,key:e[n]}));s.sort((e,s)=>(k(e.key,n),k(s.key,n),function(e,n,s){if(k(e,s),k(n,s),"string"==typeof e&&"string"==typeof n)return e<n?-1:e>n?1:0;if("number"==typeof e&&"number"==typeof n)return Math.sign(e-n);throw new t(`Cannot compare values of different types: ${typeof e} and ${typeof n}`,s)}(e.key,s.key,n)));const r=s.map(e=>e.elem);return c?r.join(""):r}{A(a,n);const t=p.map((t,n)=>({elem:t,key:e[n]}));t.sort((e,t)=>{const u=r(a,[e.key,t.key],s,n);if(u instanceof Promise)throw new TypeError("Async functions cannot be used as sort-by comparators");return x(u,n,{finite:!0}),u});const u=t.map(e=>e.elem);return c?u.join(""):u}})},arity:{min:2,max:3},docs:{category:"sequence",returns:{type:"any",rest:!0},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},keyfn:{type:"function"},comparer:{type:"function"}},variants:[{argumentNames:["seq","keyfn"]},{argumentNames:["seq","keyfn","comparer"]}],description:"Returns a sorted sequence of the items in $seq, where the sort order is determined by comparing `(keyfn item)`. If no $comparer is supplied, uses builtin `compare`.",seeAlso:["sort","compare"],examples:['let su = import(sequence); su.sort-by(["Albert", "Mojir", "Nina"], count)','let su = import(sequence); su.sort-by(["Albert", "Mojir", "Nina"], count)','let su = import(sequence); su.sort-by("Albert", lower-case, -> $2 compare $1)']}},unshift:{evaluate:([e,...t],n)=>{if(b(e,n),"string"==typeof e)return m(t,n),[...t,e].join("");const s=[...e];return s.unshift(...t),s},arity:{min:2},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:"sequence"},values:{type:"any",rest:!0}},variants:[{argumentNames:["seq","values"]}],description:"Returns copy of $seq with $values added to the beginning.",seeAlso:["push","++"],examples:["let su = import(sequence); su.unshift([1, 2, 3], 4)","let su = import(sequence); su.unshift([1, 2, 3], 4)","let su = import(sequence); su.unshift([1, 2, 3], 4, 5, 6)","\nlet su = import(sequence);\nlet l = [1, 2, 3];\nsu.unshift(l, 4);\nl"]}},distinct:{evaluate:([e],t)=>{if(b(e,t),Array.isArray(e)){const n=[];for(const s of e)g(s,t),n.some(e=>I(e,s,t))||n.push(s);return n}return Array.from(new Set(e.split(""))).join("")},arity:S(1),docs:{category:"sequence",returns:{type:"sequence"},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"Returns a copy of $seq with no duplicates.",seeAlso:["sequence.frequencies"],examples:["let su = import(sequence); su.distinct([[1], [2], [3], [1], [3], [5]])","let su = import(sequence); su.distinct([1, 2, 3, 1, 3, 5])",'let su = import(sequence); su.distinct("Albert Mojir")',"let su = import(sequence); su.distinct([])",'let su = import(sequence); su.distinct("")']}},remove:{evaluate:([e,t],n,s,{executeFunction:r})=>{A(t,n),b(e,n);return C(function(e,t){const n=[];for(let s=0;s<e.length;s++){const r=t(e[s],s);if(r instanceof Promise)return B(r,n,e,t,s);r&&n.push(e[s])}return n}(Array.isArray(e)?e:e.split(""),e=>C(r(t,[e],s,n),e=>!e)),t=>"string"==typeof e?t.join(""):t)},arity:S(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns a new sequence of items in $seq for witch `pred(item)` returns a falsy value.",seeAlso:["filter","sequence.remove-at"],examples:["let su = import(sequence); su.remove([1, 2, 3, 1, 3, 5], odd?)","let su = import(sequence); su.remove([1, 2, 3, 1, 3, 5], even?)",'let su = import(sequence); su.remove("Albert Mojir", -> "aoueiyAOUEIY" contains? $)']}},"remove-at":{evaluate:([e,t],n)=>{x(t,n,{integer:!0}),b(e,n);const s=t<0?e.length+t:t;return s<0||s>=e.length?e:Array.isArray(e)?e.filter((e,t)=>t!==s):`${e.substring(0,s)}${e.substring(s+1)}`},arity:S(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},n:{type:"number"}},variants:[{argumentNames:["seq","n"]}],description:"Returns a new sequence of all items in $seq except item at position $n. If $n is negative, it is counting from the end of the sequence.",seeAlso:["sequence.remove","sequence.splice"],examples:["let su = import(sequence); su.remove-at([1, 2, 3, 1, 3, 5], 2)",'let su = import(sequence); su.remove-at("Albert", -2)',"let su = import(sequence); su.remove-at([1, 2, 3, 1, 3, 5], 0)","let su = import(sequence); su.remove-at([1, 2, 3, 1, 3, 5], -1)",'let su = import(sequence); su.remove-at("Albert Mojir", 6)']}},"split-at":{evaluate:([e,t],n)=>{x(t,n,{integer:!0}),b(e,n);const s=t<0?e.length+t:t;return[e.slice(0,s),e.slice(s)]},arity:S(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"integer"},seq:{type:"sequence"},n:{type:"number"}},variants:[{argumentNames:["seq","n"]}],description:"Returns a pair of sequence `[take(pos input), drop(pos input)]`.",seeAlso:["sequence.split-with","take","drop"],examples:["let su = import(sequence); su.split-at([1, 2, 3, 4, 5], 2)",'let su = import(sequence); su.split-at("Albert", -2)',"let su = import(sequence); su.split-at([1, 2, 3, 4, 5], -2)",'let su = import(sequence); su.split-at("Albert", 2)']}},"split-with":{evaluate:([e,t],n,s,{executeFunction:r})=>{A(t,n),b(e,n);const u=Array.isArray(e);return C(L(u?e:e.split(""),e=>C(r(t,[e],s,n),e=>!e)),t=>-1===t?[e,u?[]:""]:[e.slice(0,t),e.slice(t)])},arity:S(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns a pair of sequences `[take-while(input, fun), drop-while(input, fun)]`.",seeAlso:["sequence.split-at","take-while","drop-while"],examples:["let su = import(sequence); su.split-with([1, 2, 3, 4, 5], odd?)","let su = import(sequence); su.split-with([1, 2, 3, 4, 5], -> $ > 3)",'let su = import(sequence); su.split-with("Albert", -> $ <= "o")']}},frequencies:{evaluate:([e],t)=>{b(e,t);return("string"==typeof e?e.split(""):e).reduce((e,n)=>(N(n,t),R(e,n)?e[n]=e[n]+1:e[n]=1,e),{})},arity:S(1),docs:{category:"sequence",returns:{type:"object"},args:{seq:{type:"sequence"}},variants:[{argumentNames:["seq"]}],description:"Returns an object from distinct items in $seq to the number of times they appear. Note that all items in $seq must be valid object keys i.e. strings.",seeAlso:["sequence.group-by","sequence.distinct","vector.count-values"],examples:['let su = import(sequence); su.frequencies(["Albert", "Mojir", "Nina", "Mojir"])','let su = import(sequence); su.frequencies("Pneumonoultramicroscopicsilicovolcanoconiosis")']}},"group-by":{evaluate:([e,t],n,s,{executeFunction:r})=>{A(t,n),b(e,n);return F(Array.isArray(e)?e:e.split(""),(e,u)=>C(r(t,[u],s,n),t=>(N(t,n),R(e,t)||(e[t]=[]),e[t].push(u),e)),{})},arity:S(2),docs:{category:"sequence",returns:{type:"object"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Returns an object of the elements of $seq keyed by the result of $fun on each element. The value at each key will be an array of the corresponding elements.",seeAlso:["sequence.frequencies","sequence.partition-by"],examples:['let su = import(sequence); su.group-by([{ name: "Albert" }, { name: "Albert" }, { name: "Mojir" }], "name")','let su = import(sequence); su.group-by([{name: "Albert"}, {name: "Albert"}, {name: "Mojir"}], "name")','let su = import(sequence); su.group-by("Albert Mojir", -> "aoueiAOUEI" contains? $ ? "vowel" : "other")']}},partition:{evaluate:(e,t)=>{const n=d(e[0],t),s=E(j(e[1],t)),r=e.length>=3?E(j(e[2],t)):s,u=4===e.length?null===e[3]?[]:function(e,t){return l(e,t),e}(e[3],t):void 0;return D(s,r,n,u,t)},arity:{min:2,max:4},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"number"},seq:{type:"sequence"},n:{type:"number"},step:{type:"number"},pad:{type:"array"}},variants:[{argumentNames:["seq","n"]},{argumentNames:["seq","n","step"]},{argumentNames:["seq","n","step","pad"]}],description:"Returns an array of sequences of $n items each, at offsets $step apart. If $step is not supplied, defaults to $n. If a $pad array is supplied, use its elements as necessary to complete last partition upto $n items. In case there are not enough padding elements, return a partition with less than $n items.",seeAlso:["sequence.partition-all","sequence.partition-by"],examples:["let su = import(sequence); su.partition(range(20), 4)","let su = import(sequence); su.partition(range(20), 4)","let su = import(sequence); su.partition(range(22), 4)","let su = import(sequence); su.partition(range(20), 4, 6)","let su = import(sequence); su.partition(range(20), 4, 3)",'let su = import(sequence); su.partition(range(20), 3, 6, ["a"])','let su = import(sequence); su.partition(range(20), 4, 6, ["a"])','let su = import(sequence); su.partition(range(20), 4, 6, ["a", "b", "c", "d"])','let su = import(sequence); su.partition(["a", "b", "c", "d", "e", "f"], 3, 1)',"let su = import(sequence); su.partition([1, 2, 3, 4], 10)","let su = import(sequence); su.partition([1, 2, 3, 4], 10, 10)","let su = import(sequence); su.partition([1, 2, 3, 4], 10, 10, [])","let su = import(sequence); su.partition([1, 2, 3, 4], 10, 10, null)",'let su = import(sequence); su.partition("superfragilistic", 5)','let su = import(sequence); su.partition("superfragilistic", 5, 5, null)',"let su = import(sequence); let foo = [5, 6, 7, 8]; su.partition(foo, 2, 1, foo)"]}},"partition-all":{evaluate:(e,t)=>{const n=d(e[0],t),s=E(j(e[1],t));return D(s,3===e.length?E(j(e[2],t)):s,n,[],t)},arity:{min:2,max:3},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"number"},seq:{type:"sequence"},n:{type:"number"},step:{type:"number"}},variants:[{argumentNames:["seq","n"]},{argumentNames:["seq","n","step"]}],description:"Returns an array of sequences like partition, but may include partitions with fewer than n items at the end.",seeAlso:["sequence.partition","sequence.partition-by"],examples:["let su = import(sequence); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)","let su = import(sequence); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)","let su = import(sequence); su.partition([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)","let su = import(sequence); su.partition-all([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 4)"]}},"partition-by":{evaluate:([e,t],n,s,{executeFunction:r})=>{A(t,n),b(e,n);const u="string"==typeof e;return C(F(u?e.split(""):e,(e,u)=>C(r(t,[u],s,n),t=>(t!==e.oldValue&&(e.result.push([]),e.oldValue=t),e.result[e.result.length-1].push(u),e)),{result:[],oldValue:void 0}),({result:e})=>u?e.map(e=>e.join("")):e)},arity:S(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"function"},seq:{type:"sequence"},fun:{type:"function"}},variants:[{argumentNames:["seq","fun"]}],description:"Applies $fun to each value in $seq, splitting it each time $fun returns a new value. Returns an array of sequences.",seeAlso:["sequence.partition","sequence.partition-all","sequence.group-by"],examples:["let su = import(sequence); su.partition-by([1, 2, 3, 4, 5], odd?)","let su = import(sequence); su.partition-by([1, 2, 3, 4, 5], -> $ == 3)","let su = import(sequence); su.partition-by([1, 1, 1, 2, 2, 3, 3], odd?)",'let su = import(sequence); su.partition-by("Leeeeeerrroyyy", identity)']}},"ends-with?":{evaluate:([e,t],n)=>(b(e,n),"string"==typeof e?(N(t,n),e.endsWith(t)):I(q(e.at(-1),n),q(t,n),n)),arity:S(2),docs:{category:"sequence",returns:{type:"boolean"},args:{a:{type:"sequence"},b:{type:"sequence"},seq:{type:"sequence"},suffix:{type:"sequence"}},variants:[{argumentNames:["seq","suffix"]}],description:"Returns `true` if $seq ends with $suffix, otherwise `false`.",seeAlso:["sequence.starts-with?"],examples:["let su = import(sequence); su.ends-with?([[1], [2], [3], [4], [5]], [5])","let su = import(sequence); su.ends-with?([[1], [2], [3], [4], [5]], 5)","let su = import(sequence); su.ends-with?([1, 2, 3, 4, 5], 5)","let su = import(sequence); su.ends-with?([1, 2, 3, 4, 5], [5])",'let su = import(sequence); su.ends-with?("Albert", "rt")','let su = import(sequence); su.ends-with?("Albert", "RT")']}},"starts-with?":{evaluate:([e,t],n)=>(b(e,n),"string"==typeof e?(N(t,n),e.startsWith(t)):I(q(e[0],n),q(t,n),n)),arity:S(2),docs:{category:"sequence",returns:{type:"boolean"},args:{a:{type:"sequence"},b:{type:"sequence"},seq:{type:"sequence"},prefix:{type:"sequence"}},variants:[{argumentNames:["seq","prefix"]}],description:"Returns `true` if $seq starts with $prefix, otherwise `false`.",seeAlso:["sequence.ends-with?"],examples:["let su = import(sequence); su.starts-with?([[1], [2], [3], [4], [5]], [1])","let su = import(sequence); su.starts-with?([1, 2, 3, 4, 5], 1)","let su = import(sequence); su.starts-with?([1, 2, 3, 4, 5], [1])",'let su = import(sequence); su.starts-with?("Albert", "Al")','let su = import(sequence); su.starts-with?("Albert", "al")']}},interleave:{evaluate:([...e],t)=>{const n="string"==typeof e[0],s=n?e.map(e=>(N(e,t),e.split(""))):e.map(e=>(l(e,t),e)),r=Math.min(...s.map(e=>e.length)),u=[];for(let e=0;e<r;e+=1)for(const t of s)e<t.length&&u.push(t[e]);return n?u.join(""):u},arity:{min:1},docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"sequence"},seqs:{type:"sequence",rest:!0}},variants:[{argumentNames:["seqs"]}],description:"Returns a sequence of the first item from each of the $seqs, then the second item from each of the $seqs, until all items from the shortest seq are exhausted.",seeAlso:["sequence.interpose","zipmap"],examples:["let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6])",'let su = import(sequence); su.interleave("Albert", ".,.,.,")',"let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [7, 8, 9])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [7, 8])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [7])","let su = import(sequence); su.interleave([1, 2, 3], [4, 5, 6], [])","let su = import(sequence); su.interleave([1, 2, 3], [])","let su = import(sequence); su.interleave([])"]}},interpose:{evaluate:([e,t],n)=>{if(b(e,n),"string"==typeof e)return N(t,n),e.split("").join(t);if(0===e.length)return[];const s=[];for(let n=0;n<e.length-1;n+=1)s.push(e[n],t);return s.push(e[e.length-1]),s},arity:S(2),docs:{category:"sequence",returns:{type:"sequence"},args:{a:{type:"sequence"},b:{type:"any"},seq:{type:"sequence"},separator:{type:"any"}},variants:[{argumentNames:["seq","separator"]}],description:"Returns a sequence of the elements of $seq separated by $separator. If $seq is a string, the separator must be a string.",seeAlso:["sequence.interleave","join"],examples:['let su = import(sequence); su.interpose("Albert", "-")','let su = import(sequence); su.interpose([1, 2, 3, 4, 5], "a")','let su = import(sequence); su.interpose(["Albert", "Mojir", "Nina"], ", ")','let su = import(sequence); su.interpose("Albert", ".")']}}};function D(e,t,n,s,r){x(t,r,{positive:!0});const u="string"==typeof n,i=[];let o=0;e:for(;o<n.length;){const r=[];for(let u=o;u<o+e;u+=1)if(u>=n.length){const e=u-n.length;if(!s){o+=t;continue e}if(e>=s.length)break;r.push(s[e])}else r.push(n[u]);i.push(r),o+=t}return u?i.map(e=>e.join("")):i}const J={name:"sequence",functions:U};export{J as sequenceUtilsModule}; //# sourceMappingURL=sequence.esm.js.map