xxl.mathematica.functional.Fold Maven / Gradle / Ivy
package xxl.mathematica.functional;
import java.util.List;
import java.util.function.BiFunction;
/**
* 折叠
*/
public class Fold {
/**
* 给出 {x,f[x,a],f[f[x,a],b]}.
*
* @param function
* @param initValue
* @param list 列表
* @param
* @return
*/
public static T fold(BiFunction function, T initValue, List list) {
return io.vavr.collection.List.ofAll(list)
.fold(initValue, function);
}
/**
* 给出 {x,f[x,a],f[f[x,a],b]}.
*
* @param function
* @param list 列表
* @param
* @return
*/
public static T fold(BiFunction function, List list) {
return io.vavr.collection.List.ofAll(list)
.subSequence(1)
.fold(list.get(0), function);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy