From 61d7a998a5e1bad14d7fa826a2332eb26aa7998e Mon Sep 17 00:00:00 2001 From: Dierk Koenig Date: Sat, 2 Sep 2023 23:09:28 +0200 Subject: [PATCH] change: include Walk as an alias for Range to allow easier discovery with the auto-import feature. --- contrib/p6_wild_wyss/README.md | 3 +++ .../kolibri/sequence/constructors/range/range.js | 11 ++++++++--- .../sequence/constructors/range/rangeTest.js | 15 ++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/contrib/p6_wild_wyss/README.md b/contrib/p6_wild_wyss/README.md index d067050d..79984ed2 100644 --- a/contrib/p6_wild_wyss/README.md +++ b/contrib/p6_wild_wyss/README.md @@ -1,3 +1,6 @@ copied over from git@github.com:wildwyss/Kolibri.git main branch as of 2023-09-01 T 14:21:43 MESZ + +## Changes to the documented API: +- introduce Walk as an alias for Range to support better discovery. diff --git a/docs/src/kolibri/sequence/constructors/range/range.js b/docs/src/kolibri/sequence/constructors/range/range.js index d40b77a9..cb13bfb8 100644 --- a/docs/src/kolibri/sequence/constructors/range/range.js +++ b/docs/src/kolibri/sequence/constructors/range/range.js @@ -1,8 +1,6 @@ import { Sequence } from "../sequence/Sequence.js"; -export { Range } - -// todo dk: think about renaming the Range ctor as it conflicts with https://developer.mozilla.org/en-US/docs/Web/API/Range +export { Range, Walk } /** * Creates a range of numbers between two inclusive boundaries, @@ -40,6 +38,13 @@ const Range = (firstBoundary, secondBoundary = 0, step = 1) => { return Sequence(left, value => !hasReachedEnd(stepIsNegative, value, right), value => value + step); }; +/** Walk is an alias for {@link Range} that allows for easier discovery since the name "Range" is also + * used within the dom API [https://developer.mozilla.org/en-US/docs/Web/API/Range], which + * undermines the auto-import when typing "Range" for the first time in a file. + * Just typing "Walk" and using the auto-import will lead to here. + */ +const Walk = Range; + /** * Sorts the two parameter a and b by its magnitude. * @param { Number } a diff --git a/docs/src/kolibri/sequence/constructors/range/rangeTest.js b/docs/src/kolibri/sequence/constructors/range/rangeTest.js index b024f7f3..76a3f870 100644 --- a/docs/src/kolibri/sequence/constructors/range/rangeTest.js +++ b/docs/src/kolibri/sequence/constructors/range/rangeTest.js @@ -1,4 +1,4 @@ -import { Range } from "./range.js" +import { Range, Walk} from "./range.js"; import { TestSuite } from "../../../util/test.js"; import { iteratorOf } from "../../util/sequenceUtil/iteratorOf.js"; import { createMonadicSequence } from "../../util/sequenceUtil/createMonadicSequence.js"; @@ -32,6 +32,19 @@ testSuite.add("test typical case for of", assert => { assert.is(result.length, 2); }); +testSuite.add("test Walk alias", assert => { + // Given + const result = []; + + // When + for(const value of Walk(1)){ + result.push(value); + } + + // Then + assert.is(result.length, 2); +}); + testSuite.add("test typical case spread", assert => { // When const result = [...Range(2)];