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(mergeScan): Add index to the accumulator function #4458

Merged
merged 5 commits into from
Jan 30, 2019

Conversation

martinsik
Copy link
Contributor

Description:
This PR adds index parameter to the accumulator function used by mergeScan just like in most other operators.

of('a', 'b', 'c', 'd').pipe(
  mergeScan((acc, x, index) => {
    console.log(index); // prints: 0, 1, 2, 3
    return of(x);
  }, 0)
).subscribe();

Related issue (if exists):
Closes #4441

@coveralls
Copy link

coveralls commented Jan 8, 2019

Pull Request Test Coverage Report for Build 8001

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 96.91%

Totals Coverage Status
Change from base Build 7999: 0.0%
Covered Lines: 5770
Relevant Lines: 5954

💛 - Coveralls

Copy link
Collaborator

@cartant cartant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but would you be able to re-write the test to use marble diagram?

@benlesh
Copy link
Member

benlesh commented Jan 9, 2019

@cartant I think the test is fine given it's just asserting the index is being passed to the function.

@@ -21,6 +21,10 @@ it('should support a currency', () => {
const o = of(1, 2, 3).pipe(mergeScan((acc, value) => of(acc + value), '', 47)); // $ExpectType Observable<string>
});

it('should support an index parameter', () => {
const o = of(1, 2, 3).pipe(mergeScan((acc, value, index) => of(index), 0)); // $ExpectType Observable<number>
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this new test is unnecessary. :)

Copy link
Collaborator

@cartant cartant Jan 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this test will fail if the index is removed from the signature, so it guards against a regression, IMO.

Nah. You're right. The spec will fail first. Duh.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this test. I was looking at how is this thing tested elsewhere and it seemed to be the same usecase as here https://github.com/ReactiveX/rxjs/blob/master/spec-dtslint/operators/map-spec.ts#L12-L14 or here https://github.com/ReactiveX/rxjs/blob/master/spec-dtslint/operators/findIndex-spec.ts#L8-L10

Copy link
Collaborator

@cartant cartant Jan 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd favour the dtslint typing tests being written without regard to what's tested in the specs - even if that means there are some redundant tests.

return of(x);
}, 0)).subscribe();

expect(recorded).to.deep.equal(expected);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please move expected inside of equal here? It will make the test moderately more readable, IMO.

@martinsik martinsik force-pushed the feat-4441-add-index-to-mergeScan branch from 705e8cb to dfd6213 Compare January 9, 2019 09:18
@rxjs-bot
Copy link

Warnings
⚠️

commit message does not follows conventional change log (1)

(1) : RxJS uses conventional change log to generate changelog automatically. It seems some of commit messages are not following those, please check contributing guideline and update commit messages.

Generated by 🚫 dangerJS

@benlesh benlesh merged commit f5e143d into ReactiveX:master Jan 30, 2019
@benlesh
Copy link
Member

benlesh commented Jan 30, 2019

Thank you, @martinsik!

@lock lock bot locked as resolved and limited conversation to collaborators Mar 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants