import { Stream } from '@motorcycle/types' import { sample } from './sample' /** * Given each event occurrence from a sampler stream takes the latest value from * the given stream. * * @name sampleWith(sampler: Stream, stream: Stream): Stream * @example * import { sampleWith } from '@motorcycle/stream' * * function submit(dom: DomSource): Stream { * const button = query('button', dom) * const input = query('input', dom) * * const click$ = events('click', button) * const value$ = map(ev => ev.target.value, events('input', input)) * * return sampleWith(click$, value$) * } */ export const sampleWith = sample(takeRight) as SampleWith export interface SampleWith { (sampler: Stream, stream: Stream): Stream (sampler: Stream): (stream: Stream) => Stream (sampler: Stream): (stream: Stream) => Stream } function takeRight(_: any, value: A): A { return value }