Last active
May 10, 2023 13:57
-
-
Save wmakeev/140da03af6fbb749eb08b1dba75069ba to your computer and use it in GitHub Desktop.
[highland enrich transform] #highland #transform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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)); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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