-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.ts
25 lines (22 loc) · 797 Bytes
/
map.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { IntermediateStage } from '../../stages';
class MapStage<IN, U> extends IntermediateStage<IN, U> {
constructor(private readonly _mapper: (element: IN) => U) {
super();
}
override consume(element: IN, hasMoreDataUpstream: boolean): void {
this._downstream.consume(this._mapper(element), hasMoreDataUpstream);
}
}
/**
* Return an intermediate stage that transforms each element according the provided mapping function.
*
* @param mapper
*
* @template IN The type parameter of each incoming element in the pipeline.
* @template OUT The type parameter of each outgoing element to be forwarded to the downstream stage.
*
* @returns
*/
export function map<IN, OUT>(mapper: (element: IN) => OUT): IntermediateStage<IN, OUT> {
return new MapStage<IN, OUT>(mapper);
}