0

目标是将流中的项目分组为多个组。分别对这些组运行转换,然后将所有组重新组合成一个流。

之后我可以使用的唯一调用group似乎是each并且不会将单个组传递给我的回调,它会传递整个分组对象的字典。调用map不会将任何内容传递给我的回调。例子:

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. 

我怎样才能做到这一点?

4

2 回答 2

0

你在找这个吗?:

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

如果不是,请尝试举例说明您希望如何处理您的数据。

于 2019-04-12T16:59:18.413 回答
0
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(() => {});
于 2022-02-02T19:35:53.730 回答