Skip to content

Commit

Permalink
feat(transducers): add normRange() iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed May 10, 2018
1 parent bd1fba3 commit 55f29b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/transducers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export * from "./iter/concat";
export * from "./iter/cycle";
export * from "./iter/iterate";
export * from "./iter/keys";
export * from "./iter/norm-range";
export * from "./iter/pairs";
export * from "./iter/permutations";
export * from "./iter/range";
Expand Down
18 changes: 18 additions & 0 deletions packages/transducers/src/iter/norm-range.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Yields sequence of `n+1` monotonically increasing numbers in the
* closed interval (0.0 .. 1.0). If `n <= 0`, yields nothing.
*
* ```
* [...normRange(4)]
* // [0, 0.25, 0.5, 0.75, 1.0]
* ```
*
* @param n number of steps
*/
export function* normRange(n: number) {
if (n > 0) {
for (let i = 0; i <= n; i++) {
yield i / n;
}
}
}

0 comments on commit 55f29b8

Please sign in to comment.