Skip to content

Commit

Permalink
change: include Walk as an alias for Range to allow easier discovery …
Browse files Browse the repository at this point in the history
…with the auto-import feature.
  • Loading branch information
Dierk Koenig committed Sep 2, 2023
1 parent 0465cad commit 61d7a99
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions contrib/p6_wild_wyss/README.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 8 additions & 3 deletions docs/src/kolibri/sequence/constructors/range/range.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion docs/src/kolibri/sequence/constructors/range/rangeTest.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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)];
Expand Down

0 comments on commit 61d7a99

Please sign in to comment.