import { Stream } from '@motorcycle/types' import { curry2 } from '@typed/prelude' import { map } from './map' import { map as mapArray } from '@typed/list' /** * Applies a function to all Sinks in a list of Sinks. * * @name mapList(f: (value: A, index: number) => B, sinksList$: Stream>): Stream> * @example * import { mapList } from '@motorcycle/stream' * * function Component(sources) { * const { listOfData$ } = sources * * const sinksList$: Stream> = mapList( * data => ChildComponent({ ...sources, data$: now(data) })), * listOfData$, * ) * * const childViews$: Stream> = * mapList(({ view$ }) => view$, sinksList$) * * ... * } */ export const mapList: MapList = curry2(__mapList) export type MapList = { (f: (value: A, index: number) => B, list$: Stream>): Stream> (f: (value: A, index: number) => B): ( list$: Stream> ) => Stream> } function __mapList( f: (value: A) => B, list$: Stream> ): Stream> { return map, ReadonlyArray>(mapArray(f), list$) }