Skip to content

Commit

Permalink
feat(spread): Add a spread helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Oct 28, 2018
1 parent 6c46201 commit ebd0815
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/operators/index.ts
Expand Up @@ -25,6 +25,7 @@ export * from "./refCountDelay";
export * from "./refCountForever";
export * from "./refCountOn";
export * from "./reschedule";
export * from "./spread";
export * from "./startWithDeferred";
export * from "./startWithTimeout";
export * from "./subsequent";
Expand Down
27 changes: 27 additions & 0 deletions source/operators/spread-spec.ts
@@ -0,0 +1,27 @@
/**
* @license Use of this source code is governed by an MIT-style license that
* can be found in the LICENSE file at https://github.com/cartant/rxjs-etc
*/
/*tslint:disable:no-unused-expression*/

import { filter, map } from "rxjs/operators";
import { marbles } from "rxjs-marbles";
import { spread } from "./spread";

describe("spread", () => {

it("should pipe the specified operators", marbles((m) => {

const source = m.cold("-a-b-c-|");
const subs = "^------!";
const expected = m.cold("-A---C-|)");

const operators = [
filter(value => value !== "b"),
map((value: string) => value.toUpperCase())
];
const destination = source.pipe(spread(...operators));
m.expect(destination).toBeObservable(expected);
m.expect(source).toHaveSubscriptions(subs);
}));
});
10 changes: 10 additions & 0 deletions source/operators/spread.ts
@@ -0,0 +1,10 @@
/**
* @license Use of this source code is governed by an MIT-style license that
* can be found in the LICENSE file at https://github.com/cartant/rxjs-etc
*/

import { OperatorFunction } from "rxjs";

export function spread<T, R>(...operations: OperatorFunction<any, any>[]): OperatorFunction<T, R> {
return source => operations.reduce((acc, operator) => acc.pipe(operator), source);
}

0 comments on commit ebd0815

Please sign in to comment.