简体   繁体   English

"在highlandjs中调用`group`后调用转换"

[英]Calling transformations after `group` call in highlandjs

The goal is to group items in a stream into multiple groups.目标是将流中的项目分组为多个组。 Run transformations on those groups separately and then re-combine all the groups into one stream.分别对这些组运行转换,然后将所有组重新组合成一个流。

The only call I can use after group<\/code> seems to be each<\/code> and that doesn't pass individual groups to my callback it passes the entire dictionary of grouped objects.我可以在group<\/code>之后使用的唯一调用似乎是each<\/code>并且不会将单个组传递给我的回调,它会传递整个分组对象字典。 Calling map<\/code> won't pass anything to my callback.调用map<\/code>不会将任何内容传递给我的回调。 Example:例子:

const groups = stream.group(func);
groups.map(item => console.log(item)); // prints nothing
groups.each(item => console.log(item)); // instead of item being one of the groups created, it's a dictionary with all the groups included. 

are you looking for doing this ? 你在找这个吗? :

groups.on('error', handleError)
        .pipe(transformObject(async item => {
            some code...

If non, please try to give an example of what you want to do with your data. 如果不是,请尝试举例说明您要对数据执行的操作。

import highland from 'highland'; const source = highland([ { age: 21, name: 'Alice' }, { age: 42, name: 'Bob' }, { age: 42, name: 'Carol' } ]); source .group(person => person.age) .flatMap(highland.values) // Apply transformation to each group here .map(group => group) .flatten(1) .doto(console.log) .done(() => {});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM