From 44f4a97b9557eddcfeea959be237d451b607e8c8 Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Wed, 5 Jul 2023 16:28:50 +0200 Subject: [PATCH] feat: map operator correction --- src/operators/map.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/operators/map.ts b/src/operators/map.ts index 7005351..287c595 100644 --- a/src/operators/map.ts +++ b/src/operators/map.ts @@ -2,7 +2,22 @@ import { Observable } from '../Observable'; import { OperatorFunction } from './types'; export function map(project: (value: T) => R): OperatorFunction { - void Observable; - void project; - throw new Error('TODO'); + return source => { + return new Observable(observer => { + const next = (value: T) => { + try { + const result = project(value); + observer.next(result); + } catch (e) { + observer.error(e); + } + }; + + return source.subscribe({ + next, + error: err => observer.error(err), + complete: () => observer.complete(), + }); + }); + }; }