-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/array/operators/transformation/array-concat.operator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
src/array/operators/transformation/array-concat.operator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], [])); | ||
} |
1 change: 0 additions & 1 deletion
1
src/array/operators/transformation/collect-array.operator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters