Skip to content

Commit

Permalink
fix: proper typing on foreach return inside the pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsisexistence committed Aug 28, 2022
1 parent 1e90713 commit 799a66c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/filter/filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Kind } from '../common';

// export type FilterFn<T> = (value: T, index: number) => boolean;
export type Filter<T> = {
kind: Kind.FILTER;
run: (value: T, index: number) => T;
Expand Down
7 changes: 3 additions & 4 deletions src/forEach/forEach.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { Kind } from '../common';

export type ForEachFn<T> = (value: T, index: number) => void;
export type ForEach<T> = {
kind: Kind.FOR_EACH;
run: ForEachFn<T>;
run: (value: T, index: number) => T;
};

/**
* rxjs "tap" analogue
* does not change array values
*/
export function forEach<TValue>(fn: ForEachFn<TValue>): ForEach<TValue> {
export function forEach<T>(fn: (value: T, index: number) => void): ForEach<T> {
return {
kind: Kind.FOR_EACH,
run: fn
run: fn as (value: T, index: number) => T,
};
}
11 changes: 11 additions & 0 deletions src/fuzion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ describe('fuzion', () => {
).toEqual([false, false]);
});

test('should do nothing in foreach, then filter and map values', () => {
expect(
fuzion(
[true, false, true],
forEach(() => {}),
filter(a => a === true),
map(a => !a),
),
).toEqual([false, false]);
});

test('should apply 9 operators', () => {
expect(
fuzion(
Expand Down

0 comments on commit 799a66c

Please sign in to comment.