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

前端 未结 7 1103
北海茫月
北海茫月 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条回答
  •  猫巷女王i
    2020-12-18 20:38

    Why re-invent from scratch when we have solutions. This functionality is present in lodash/RxJS/stream.js.

    Example snippet from lodash:

    _.flow(
     _.assign(rows[0]),
     _.omit('blah')
    )(foundUser);
    
    // >> {"charData":[],"ok": 1}
    

    However, javascript runs on single thread and so do these libraries. Java streams benefit from multi core systems(in case of parallel). There they can use multiple threads to use all available cores.

提交回复
热议问题