feat: map operator correction

This commit is contained in:
Guillaume ARM 2023-07-05 16:28:50 +02:00
parent 346bbd851a
commit 44f4a97b95

View File

@ -2,7 +2,22 @@ import { Observable } from '../Observable';
import { OperatorFunction } from './types';
export function map<T, R>(project: (value: T) => R): OperatorFunction<T, R> {
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(),
});
});
};
}