* Parse the regression argument list: an optional trailing variable symbol, * an optional trailing integer degree (for `PolynomialFit`), and the data as * either two collections or one collection of pairs.
( ops: ReadonlyArray<Expression>, wantDegree: boolean )
| 998 | // `SlidingWindow("abcd", 2)` is `["ab","bc","cd"]` (ruling D9(b), |
| 999 | // 2026-08-16; see `innerRun` in `library/collections.ts`). Spelled as a |
| 1000 | // BOUNDED type variable (`S where S: string`), never the ground type |
| 1001 | // `string`: an `unknown`- or `any`-typed operand refutes no arm, so a |
| 1002 | // ground `string` parameter would win most-specific-wins on every |
| 1003 | // untyped operand. |
| 1004 | signature: |
| 1005 | '((S, integer, integer?) -> list<string> where S: string) & ((collection, integer, integer?) -> list<list>)', |
| 1006 | examples: [ |
| 1007 | 'SlidingWindow([1, 2, 3, 4], 2) // Returns [[1,2], [2,3], [3,4]]', |
| 1008 | 'SlidingWindow("abcd", 2) // Returns ["ab", "bc", "cd"]', |
| 1009 | ], |
| 1010 | evaluate: ([xs, winArg, stepArg], { engine: ce }) => { |
| 1011 | if (!xs.isFiniteCollection) return undefined; |
| 1012 | // Small finite sources materialize eagerly (all existing semantics); |
| 1013 | // larger — or unknown-length — sources stay symbolic and are served |
| 1014 | // lazily by the `collection` handlers below (Tycho item 52). |
| 1015 | const size = xs.count; |
| 1016 | if (size === undefined || size > MAX_SIZE_EAGER_COLLECTION) |
| 1017 | return undefined; |
| 1018 | const windowSize = toInteger(winArg); |
| 1019 | const stepSize = stepArg ? toInteger(stepArg) : 1; |
| 1020 | if ( |
| 1021 | windowSize === null || |
| 1022 | windowSize <= 0 || |
| 1023 | stepSize === null || |
| 1024 | stepSize <= 0 |
| 1025 | ) |
| 1026 | return undefined; |
| 1027 | |
| 1028 | const data = Array.from(xs.each()) as Expression[]; |
| 1029 | const result: Expression[] = []; |
| 1030 | |
| 1031 | // Each window is emitted through `innerRun`, which makes it a STRING |
| 1032 | // when the source is a string. Joining a window's grapheme clusters |
| 1033 | // re-runs segmentation, and two adjacent clusters can merge — but only |
| 1034 | // when the source itself contained a lone combining mark, the only way |
| 1035 | // a cluster can begin with a character that attaches to what precedes |
no test coverage detected