Javascript equivalents for Java Streams API

一世执手 提交于 2019-12-22 06:40:27

问题


I like the Java 8's streaming API. There are plenty of useful intermediate and terminal methods to transform and collect the stream. I'm talking about intermediate methods like distinct() or terminal methods like collect(). I find the Collector API especially useful, to reduce the stream to deep grouping maps.

What is the javascript equivalent for the Java streaming API? I know there're basic functions like map, filter and reduce, but don't find any more generalized interfaces provided by javascript native to query or group the data in collection. Are there some production ready libraries to match the Java Streaming API?


回答1:


java 8 stream() is the same as lodash chain()

java 8 collect() is the same as lodash value()

java 8 distinct() is the same as lodash uniq()

java 8 map() is the same as lodash map()

lodash is more comprehensive, since it has been around longer.




回答2:


From the api level, lodash/RxJS/stream.js may meet the requirement, but the powerful thing of Java Stream is it can leverage the modern cpu multi core architecture so to parallelize the jobs. However, this is not solved by any of these pure js libraries, at then end of the day, these js are still running in a single threaded runtime, and has 1 core usage at the same time.

I guess the JS engine needs to provide support to achieve the performance target.



来源:https://stackoverflow.com/questions/43408033/javascript-equivalents-for-java-streams-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!