/
lameach
/
fastcombinators
Обзор
Документация
Войти
/
lameach
/
fastcombinators
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/core/map.ts
32 строки
847 B
Daniil Botvinnikov
Initial commit: FastCombinators library
08 дек 2025, 18:39
08 дек 2025, 18:39
3af0bba
Код
Авторство
О чём код?
import { Sink, SinkFactory } from "../interfaces/sink"; class MapSink<TIn, TOut, TResult> implements Sink<TIn, TResult> { constructor( private readonly downstream: Sink<TOut, TResult>, private readonly fn: (v: TIn) => TOut ) {} next(value: TIn): boolean { return this.downstream.next(this.fn(value)); } complete(): TResult { return this.downstream.complete(); } } /** * Transforms each element using the provided function. * * @template TIn Input element type * @template TOut Output element type * @param fn - Transformation function * @returns A transducer that applies the transformation * * @example * ```typescript * const doubled = map((x: number) => x * 2); * ``` */ export const map = <TIn, TOut>(fn: (v: TIn) => TOut): SinkFactory<TIn, TOut> => (downstream) => new MapSink(downstream, fn);