java - C+ +'s accumulate or Groovy' 注入(inject)的 Java 等价物是什么?

标签 java functional-programming

从本质上讲,我想一次性完成以下操作:

        int sum = initialValue;
        for (int n : collectionOfInts) {
            sum += n;
        }
        return sum;

我看到有 http://functionaljava.org/examples/1.5/#Array.foldLeft ,但我宁愿不必复制该集合。

最佳答案

I see that there's http://functionaljava.org/examples/1.5/#Array.foldLeft, but I'd rather not have to copy the collection.

如果您使用 IterableW 中的 foldLeft|而不是数组,您无需复制任何内容。

关于java - C+ +'s accumulate or Groovy' 注入(inject)的 Java 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8496967/

相关文章:

haskell - 无法推断读取类型约束

inheritance - F# 和继承建模

java - biojava包导入错误

java - 禁用一组 JButton 中特定 JButton 的 mouseEvent

java - 无法从 Android 手机访问 pdf 中的链接

lambda - 以标签作为参数的 F# 函数

php - 无法从 php 类调用全局函数

java - 更改 Stream 的 map 函数中字段的值

java - Angular 2 应用程序部署在 JBOSS 6.4 eap 上,以 java 服务作为后端

java - Android - 可见和不可见的按钮