Skip to content

Commit

Permalink
feat: ✨️ 添加sum操作符
Browse files Browse the repository at this point in the history
  • Loading branch information
hackers267 committed Aug 24, 2022
1 parent 42b359f commit b50e3ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/operator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./toDesc";
export * from "./toPage";
export * from "./toOption";
export * from "./toVirtualPage";
export * from "./sum";
13 changes: 13 additions & 0 deletions src/operator/sum.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { from } from "rxjs";
import { sum } from "./sum";

describe("sum", function () {
it("should be right", function (done) {
from([1, 2, 3, 4])
.pipe(sum())
.subscribe((x) => {
expect(x).toBe(10);
done();
});
});
});
5 changes: 5 additions & 0 deletions src/operator/sum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { pipe, reduce } from "rxjs";

export function sum() {
return pipe(reduce<number, number>((acc, cur) => acc + cur, 0));
}

0 comments on commit b50e3ad

Please sign in to comment.