Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Last active May 10, 2023 13:57
Show Gist options
  • Save wmakeev/140da03af6fbb749eb08b1dba75069ba to your computer and use it in GitHub Desktop.
Save wmakeev/140da03af6fbb749eb08b1dba75069ba to your computer and use it in GitHub Desktop.
[highland enrich transform] #highland #transform
/**
* Enrich source stream items with some data
*
* @param pick Function that transform source item to pass result to enrichment transform
* @param enrichmentData Enrichment transformation, which returns the data stream with which the original stream will be enriched
* @param compose Function that enrich source item with enrichment data
* @type {EnrichTransform}
*/
export const enrichTransform = (pick, enrichmentData, compose) => (source$) => {
return source$
.map(pick)
.through(enrichmentData)
.zip(source$.observe())
.map(([data, src]) => compose(src, data));
};
type EnrichTransform = <Src, Pick, Data, Res>(
pick: (item: Src) => Pick,
enrichmentData: (source$: Highland.Stream<Pick>) => Highland.Stream<Data>,
compose: (item: Src, data: Data) => Res
) => (source$: Highland.Stream<Src>) => Highland.Stream<Res>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment