import { checkFunction } from "../_check" import { Source } from "../_core" import { Projection } from "../_interfaces" import { In, Out } from "../_interfaces" import { makeObservable } from "../_obs" import { Transaction } from "../_tx" import { curry2 } from "../_util" import { dispatcherOf, Observable } from "../Observable" import { Identity } from "./_base" export const mapError: CurriedMapError = curry2(_mapError) export interface CurriedMapError { ( project: Projection, observable: In, ): Out (project: Projection): ( observable: In, ) => Out } function _mapError(project: Projection, observable: Observable): Observable { checkFunction(project) return makeObservable(observable, new MapError(dispatcherOf(observable), project)) } class MapError extends Identity { constructor(source: Source, private p: Projection) { super(source) } public error(tx: Transaction, err: Error): void { const { p } = this this.sink.next(tx, p(err)) } }