番石榴是否具有与Python的缩小功能相同的功能? [英] Does guava have an equivalent to Python's reduce function?

查看:111
本文介绍了番石榴是否具有与Python的缩小功能相同的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在寻找类似于

在Python中,guava(或另一个java库) ://docs.python.org/library/functions.html#reduce> http://docs.python.org/library/functions.html#reduce

map 和减少。 (我排除了并行/分布式处理框架中的map / reduce功能......因为这些框架需要一个大的问题才是值得的。)

可能这种缺乏的原因是没有关闭的地图/缩减编码太麻烦。样板代码太多,语法过重。由于在简单集合上使用map / reduce原语的主要目的是让你的代码简单而优雅......




@CurtainDog提供了 lambdaj 的链接。那是OP之后的事情(尽管没有专门称为 reduce 的方法)。但它说明了我对样板的看法。请注意,许多高阶操作涉及创建扩展 Closure 类中的一个或另一个类的类。



( FWIW,我认为 Lambda.aggregate(。 ..) 方法是 reduce 的lambdaj模拟。)


Does guava (or another java library) have something like reduce() function in Python?

I'm looking for something like this http://docs.python.org/library/functions.html#reduce

解决方案

I've not (yet) managed to find any Java collections libraries that support map and reduce. (I exclude map/reduce functionality in parallel / distributed processing frameworks ... because you need a "big" problem for these frameworks to be worthwhile.)

Probably, the reason for this "lack" is that map/reduce coding without closures is just too cumbersome. Too much boilerplate code, too much heavy-weight syntax. Since the main point of using map / reduce primitives on simple collections is to make your code simple and elegant ...


@CurtainDog contributed a link to lambdaj. That does the kind of thing that the OP is after (though there's no method specifically called reduce). But it illustrates what I was saying about boilerplate. Notice that many of the higher order operations involve creating classes that extend one or other of the Closure classes.

(FWIW, I think that the Lambda.aggregate(...) methods are the lambdaj analog of reduce.)

这篇关于番石榴是否具有与Python的缩小功能相同的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆