Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(range): accept one argument #4360

Merged
merged 1 commit into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -24,7 +24,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 @@ -34,9 +34,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