How can I perform operations in JavaScript just like we do pipeline of operations in Java streams?

前端 未结 7 1055
北海茫月
北海茫月 2020-12-18 20:07

In Java 8 using streams when I chain methods one after the another the execution of operations are performed in pipelined manner.

Example:

List

        
相关标签:
7条回答
  • 2020-12-18 20:46

    I would suggest to use libraries like RxJS. This gives you more control over the kind of processing, should it be sequential, parallel or whatsoever.

    Here is an example, which is close to what you expect:

    const source = Rx.Observable.from([{name: 'Joe', age: 30}, {name: 'Frank', age: 20},{name: 'Ryan', age: 50}]);
    const example = source.map(person => {
      console.log("Mapping1" + person.name)
      return person.name
    });
    const subscribe = example.subscribe(val => console.log(val));
    

    outputs:

    "Mapping1Joe"
    "Joe"
    "Mapping1Frank"
    "Frank"
    "Mapping1Ryan"
    "Ryan"
    
    0 讨论(0)
提交回复
热议问题