import type { Observable } from "rxjs"; import type { MaybeFuture, Observer, Present } from "../types/futures"; import { withLatestFrom, map, of, from } from "rxjs"; import { korma } from "../utils/curry"; const maybeLift = (v: MaybeFuture): Observable => (v as Observable).subscribe ? v as Observable : (v as Promise).then ? from(v as Promise) : of(v as Present) ; /** * WIP, experimental, don't use yet * Emits the latest value coming from the supplied observable */ export const AsLatestFrom = (source: MaybeFuture, target?: Observer) => { const pipeline = [ withLatestFrom(maybeLift(source)), map(([_, latest]) => latest), ]; return korma(pipeline, target); };