Skip to content

Commit

Permalink
fixing flatMapList to not wreck the original values
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusandy committed Mar 16, 2019
1 parent 51d32b0 commit 942eaab
Show file tree
Hide file tree
Showing 4 changed files with 2,123 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"coveralls": "^3.0.2",
"istanbul": "^0.4.5",
"lazy.js": "^0.5.1",
"lodash": "^4.17.10",
"lodash": "^4.17.11",
"mocha": "^5.2.0",
"mocha-lcov-reporter": "^1.3.0",
"nyc": "^12.0.2",
Expand Down
2 changes: 1 addition & 1 deletion processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class ListFlatMapProcessor<Input, Output> extends PureStatelessProcessor<Input,
} else if (this.inputs.length > 0) {
const nextSource: Optional<Input> = this.takeNextInput();
if (nextSource.isPresent()) {
this.outputList = this.Function(nextSource.get());
this.outputList = [...this.Function(nextSource.get())];
return this.processAndGetNext();
}
}
Expand Down
22 changes: 22 additions & 0 deletions test/streamTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,28 @@ describe('Stream tests', () => {
});

describe('flatMapList', () => {
it('should not consume the source list', () => {
const grid = [
[1,2,3],
[4,5,6],
[7,8,9]
];

const expected = [
[1,2,3],
[4,5,6],
[7,8,9]
];

Stream.of(grid)
.flatMapList(Function.identity())
.collect(Collectors.toList());

expect(grid[0]).to.have.members(expected[0]);
expect(grid[1]).to.have.members(expected[1])
expect(grid[2]).to.have.members(expected[2])
});

it('it should, flatten a stream of lists', () => {
const l1 = [1, 2, 3];
const l2 = [1, 2, 3];
Expand Down

0 comments on commit 942eaab

Please sign in to comment.