Skip to content

Commit

Permalink
Merge 56a5fac into d631261
Browse files Browse the repository at this point in the history
  • Loading branch information
christophka committed Mar 9, 2021
2 parents d631261 + 56a5fac commit 7ec705d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/array/operators/transformation/array-concat.operator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { TestScheduler } from 'rxjs/testing';

import { arrayConcat } from './array-concat.operator';

describe('array/operators/switch-expand-items', () => {
let testScheduler: TestScheduler;

beforeEach(() => {
testScheduler = new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected);
});
});

const inputValues = {
a: [['a']],
b: [['a'], ['b']],
c: [['a'], ['b'], ['c']],
d: [
['a', 'b'],
['c', 'd'],
],
e: [['a', 'b'], ['c', 'd'], ['e']],
};

const arrayValues = {
a: ['a'],
b: ['a', 'b'],
c: ['a', 'b', 'c'],
d: ['a', 'b', 'c', 'd'],
e: ['a', 'b', 'c', 'd', 'e'],
};

it('should concat array emissions', () => {
testScheduler.run(({ expectObservable, cold }) => {
const marbles = '(abc|)';
const source$ = cold(marbles, inputValues).pipe(arrayConcat());

expectObservable(source$).toBe(marbles, arrayValues);
});
});
});
15 changes: 15 additions & 0 deletions src/array/operators/transformation/array-concat.operator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { OperatorFunction } from 'rxjs';
import { map } from 'rxjs/operators';

/**
* @returns
* An operator that collects streams of arrays and
* emits an concatted array of the sources emission
*
* @example
* combineLatest([of(['a']), of(['b', 'c']), of(['d'])]).pipe(arrayConcat());
* // (a|) -> a: ['a', 'b', 'c', 'd']
*/
export function arrayConcat<T>(): OperatorFunction<T[][], T[]> {
return map(values => values.reduce((acc, cur) => [...acc, ...cur], []));
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { toArray } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';

import { collectArray } from './collect-array.operator';
Expand Down
1 change: 1 addition & 0 deletions src/array/operators/transformation/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './array-concat.operator';
export * from './collect-array.operator';
export * from './map-filter.operator';
export * from './map-items.operator';
Expand Down

0 comments on commit 7ec705d

Please sign in to comment.