Skip to content

Commit

Permalink
feat(range): accept one argument (#4360)
Browse files Browse the repository at this point in the history
  • Loading branch information
arpadvas authored and benlesh committed Jan 30, 2019
1 parent 6e7f407 commit a388578
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
15 changes: 15 additions & 0 deletions spec/observables/range-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ describe('range', () => {
});

});

it('should accept only one argument where count is argument and start is zero', () => {
const e1 = range(5)
.pipe(concatMap((x, i) => of(x).pipe(delay(i === 0 ? 0 : 20, rxTestScheduler))));
const expected = 'a-b-c-d-(e|)';
const values = {
a: 0,
b: 1,
c: 2,
d: 3,
e: 4
};
expectObservable(e1).toBe(expected, values);
expectObservable(e1).toBe(expected, values);
});
});

describe('RangeObservable', () => {
Expand Down
9 changes: 7 additions & 2 deletions src/internal/observable/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Observable } from '../Observable';
* @see {@link index/interval}
*
* @param {number} [start=0] The value of the first integer in the sequence.
* @param {number} [count=0] The number of sequential integers to generate.
* @param {number} count The number of sequential integers to generate.
* @param {SchedulerLike} [scheduler] A {@link SchedulerLike} to use for scheduling
* the emissions of the notifications.
* @return {Observable} An Observable of numbers that emits a finite range of
Expand All @@ -36,9 +36,14 @@ import { Observable } from '../Observable';
* @owner Observable
*/
export function range(start: number = 0,
count: number = 0,
count?: number,
scheduler?: SchedulerLike): Observable<number> {
return new Observable<number>(subscriber => {
if (count === undefined) {
count = start;
start = 0;
}

let index = 0;
let current = start;

Expand Down

0 comments on commit a388578

Please sign in to comment.