import { Scope, EventStream, EventStreamSeed, isPropertySeed, Observable, Property, PropertySeed, } from "./abstractions" import { applyScopeMaybe } from "./applyscope" import { FlatMapStreamSeed, FlatMapPropertySeed, Spawner } from "./flatmap" import { BinaryTransformOp, BinaryTransformOpScoped } from "./transform" // TODO: typing is not perfect: spawners for properties should spawn property(seed)s, not streams export function flatMapLatest( fn: Spawner< A, PropertySeed | Property | EventStream | EventStreamSeed > ): BinaryTransformOp export function flatMapLatest( fn: Spawner< A, PropertySeed | Property | EventStream | EventStreamSeed >, scope: Scope ): BinaryTransformOpScoped export function flatMapLatest(fn: Spawner, scope?: Scope): any { return (s: any) => { if (isPropertySeed(s)) { return applyScopeMaybe( new FlatMapPropertySeed([s, "flatMapLatest", [fn]], s, fn, { latest: true, }), scope ) } else { return applyScopeMaybe( new FlatMapStreamSeed([s, "flatMapLatest", [fn]], s, fn, { latest: true, }), scope ) } } }