Benyamin Noori
Benyamin Noori

Reputation: 880

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 seems to be each and that doesn't pass individual groups to my callback it passes the entire dictionary of grouped objects. Calling map won't pass anything to my callback. 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. 

How can I do that?

Upvotes: 0

Views: 92

Answers (2)

djanowski
djanowski

Reputation: 5858

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(() => {});

Upvotes: 0

Nabil CHOUKRI
Nabil CHOUKRI

Reputation: 79

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.

Upvotes: 0

Related Questions