diff --git a/docs/src/config-menu.ts b/docs/src/config-menu.ts index 98a2191..fdea4cd 100644 --- a/docs/src/config-menu.ts +++ b/docs/src/config-menu.ts @@ -98,10 +98,6 @@ export default { "text": "isEmpty", "link": "en/array/operator/isEmpty" }, - { - "text": "kernel", - "link": "en/array/operator/kernel" - }, { "text": "last", "link": "en/array/operator/last" @@ -154,6 +150,10 @@ export default { "text": "stride", "link": "en/array/operator/stride" }, + { + "text": "strideWindowed", + "link": "en/array/operator/strideWindowed" + }, { "text": "tail", "link": "en/array/operator/tail" diff --git a/docs/src/pages/en/array/operator/kernel.md b/docs/src/pages/en/array/operator/strideWindowed.md similarity index 85% rename from docs/src/pages/en/array/operator/kernel.md rename to docs/src/pages/en/array/operator/strideWindowed.md index 56d4783..5b02f61 100644 --- a/docs/src/pages/en/array/operator/kernel.md +++ b/docs/src/pages/en/array/operator/strideWindowed.md @@ -1,14 +1,14 @@ --- -title: kernel -description: kernel +title: strideWindowed +description: strideWindowed layout: ../../../../layouts/MainLayout.astro --- -Splits an array into subarrays (kernels) of a specified `windowSize`, +Splits an array into subarrays (windows) of a specified `windowSize`, moving the window by `stride` elements at a time. ## Type ```ts -type kernel = (stride: number) => (windowSize: number) => (array: T[]) => T[][] +type strideWindowed = (stride: number) => (windowSize: number) => (array: T[]) => T[][] ``` ## Parameters @@ -29,7 +29,7 @@ const inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const stride = 2; const windowSize = 3; -const resultWindows = kernel(stride)(windowSize)(inputArray); +const resultWindows = strideWindowed(stride)(windowSize)(inputArray); // -> [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9]] ``` diff --git a/docs/src/pages/en/array/operator/windowed.md b/docs/src/pages/en/array/operator/windowed.md index 155fb84..c817276 100644 --- a/docs/src/pages/en/array/operator/windowed.md +++ b/docs/src/pages/en/array/operator/windowed.md @@ -54,6 +54,6 @@ the result will be an empty array. ## See Also -- [kernel](./kernel) +- [strideWindowed](./strideWindowed) - [stride](./stride) - [pairwise](./pairwise) diff --git a/spec/core/array.spec.ts b/spec/core/array.spec.ts index c5d1853..af83dae 100644 --- a/spec/core/array.spec.ts +++ b/spec/core/array.spec.ts @@ -22,7 +22,7 @@ describe('array', () => { 'findIndexBack', 'flatten', 'fold', 'foldBack', 'forall', 'groupBy', 'head', 'init', 'insertAt', 'interleave', 'isEmpty', - 'iter', 'kernel', 'last', 'length', + 'iter', 'last', 'length', 'map', 'maxBy', 'minBy', 'pairwise', 'partition', 'push', 'reduce', 'reduceBack', 'replicate', @@ -32,8 +32,8 @@ describe('array', () => { 'sortByDescending', 'sortDescending', 'sortInPlace', 'sortInPlace', 'sortInPlaceBy', 'sortInPlaceWith', 'sortInPlaceWith', 'sortWith', 'sortWith', - 'splitAt', 'splitInto', 'stride', 'sum', - 'sumBy', 'remove', 'tail', 'take', + 'splitAt', 'splitInto', 'stride', 'strideWindowed', + 'sum', 'sumBy', 'remove', 'tail', 'take', 'takeWhile', 'takeWhileInclusive', 'transpose', 'truncate', 'tryFind', 'tryFindBack', 'tryFindIndex', 'tryFindIndexBack', 'tryHead', diff --git a/spec/core/array/operator/kernel.spec.ts b/spec/core/array/operator/strideWindowed.spec.ts similarity index 53% rename from spec/core/array/operator/kernel.spec.ts rename to spec/core/array/operator/strideWindowed.spec.ts index c72bceb..ba907ee 100644 --- a/spec/core/array/operator/kernel.spec.ts +++ b/spec/core/array/operator/strideWindowed.spec.ts @@ -1,20 +1,20 @@ import {expect} from 'chai'; import {checkThrow} from '../../../support/checkThrow'; -import {chunkBySize, kernel, range, windowed} from '../../../../src/array'; +import {chunkBySize, strideWindowed, range, windowed} from '../../../../src/array'; -describe('kernel', () => { +describe('strideWindowed', () => { - it('should kernel 1:2', () => { + it('should strideWindowed 1:2', () => { const array = [1, 2, 3, 4]; - const fn = kernel(2)(2); + const fn = strideWindowed(2)(2); expect(fn(array)).to.eql([[1, 2], [3, 4]]); expect(fn([1, 2])).to.eql([[1, 2]]); expect(fn([1])).to.eql([]); }); - it('should kernel 2:3', () => { + it('should strideWindowed 2:3', () => { const array = [1, 2, 3, 4, 5, 6, 7]; - const fn = kernel(2)(3); + const fn = strideWindowed(2)(3); expect(fn(array)).to.eql([[1, 2, 3], [3, 4, 5], [5, 6, 7]]); expect(fn([1, 2, 3])).to.eql([[1, 2, 3]]); expect(fn([1, 2])).to.eql([]); @@ -23,41 +23,41 @@ describe('kernel', () => { describe('iterate', () => { for (let i = 1; i < 50; i += Math.ceil(Math.random() * 5)) { - it(`should kernel 1:${i} equals windowed ${i}`, () => { + it(`should strideWindowed 1:${i} equals windowed ${i}`, () => { const array = range(0, 100); - const fn = kernel(1)(i); + const fn = strideWindowed(1)(i); expect(fn(array)).to.eql(windowed(i)(array)); }); - it(`should kernel ${i}:${i} equals chunkBySize ${i} if array length is multiple of ${i}`, () => { + it(`should strideWindowed ${i}:${i} equals chunkBySize ${i} if array length is multiple of ${i}`, () => { const array = range(0, Math.floor(100 / i) * i); - const fn = kernel(i)(i); + const fn = strideWindowed(i)(i); expect(fn(array)).to.eql(chunkBySize(i)(array)); }); } }); it('should return empty if window greater than length', () => { - const fn = kernel(1)(2); + const fn = strideWindowed(1)(2); expect(fn([1])).to.eql([]); }); it('should throw if windowSize is less than 1', () => { - expect(() => kernel(1)(0)).to.throw(`windowSize must not be less than 1. (0 given)`); - expect(() => kernel(1)(-1)).to.throw(`windowSize must not be less than 1. (-1 given)`); + expect(() => strideWindowed(1)(0)).to.throw(`windowSize must not be less than 1. (0 given)`); + expect(() => strideWindowed(1)(-1)).to.throw(`windowSize must not be less than 1. (-1 given)`); }); it('should throw if stride is less than 1', () => { - expect(() => kernel(0)(1)).to.throw(`stride must not be less than 1. (0 given)`); - expect(() => kernel(-1)(1)).to.throw(`stride must not be less than 1. (-1 given)`); + expect(() => strideWindowed(0)(1)).to.throw(`stride must not be less than 1. (0 given)`); + expect(() => strideWindowed(-1)(1)).to.throw(`stride must not be less than 1. (-1 given)`); }); it('should return empty', () => { - const fn = kernel(1)(2); + const fn = strideWindowed(1)(2); expect(fn([])).to.eql([]); }); it('should throw if null or undefined', () => { - const fn = kernel(1)(2); + const fn = strideWindowed(1)(2); checkThrow(fn); }); }); diff --git a/src/array/operator/index.ts b/src/array/operator/index.ts index cd47c61..c268a9c 100644 --- a/src/array/operator/index.ts +++ b/src/array/operator/index.ts @@ -31,7 +31,6 @@ export * from './insertAt'; export * from './interleave'; export * from './isEmpty'; export * from './iter'; -export * from './kernel'; export * from './last'; export * from './length'; export * from './map'; @@ -63,6 +62,7 @@ export * from './sortWith'; export * from './splitAt'; export * from './splitInto'; export * from './stride'; +export * from './strideWindowed'; export * from './sum'; export * from './sumBy'; export * from './tail'; diff --git a/src/array/operator/kernel.ts b/src/array/operator/strideWindowed.ts similarity index 91% rename from src/array/operator/kernel.ts rename to src/array/operator/strideWindowed.ts index 322e172..c4e4bb4 100644 --- a/src/array/operator/kernel.ts +++ b/src/array/operator/strideWindowed.ts @@ -1,4 +1,4 @@ -export const kernel = (stride: number) => { +export const strideWindowed = (stride: number) => { if (stride < 1) { throw Error(`stride must not be less than 1. (${stride} given)`); diff --git a/src/array/operator/windowed.ts b/src/array/operator/windowed.ts index 2beac38..5cd2391 100644 --- a/src/array/operator/windowed.ts +++ b/src/array/operator/windowed.ts @@ -1,4 +1,4 @@ -import {kernel} from './kernel'; +import {strideWindowed} from './strideWindowed'; -export const windowed = kernel(1) +export const windowed = strideWindowed(1)