阅读权限 255 威望 1 级论坛币 49635 个 通用积分 55.6937 学术水平 370 点 热心指数 273 点 信用等级 335 点 经验 57805 点 帖子 4005 精华 21 在线时间 582 小时 注册时间 2005-5-8 最后登录 2023-11-26
Fold
Fold rolls out the KeyedDataStream by combining the last folder stream with the current record. It emits a data stream back.
In Java:
keyedInputStream keyedStream.fold("Start", new FoldFunction<Integer, String>() {
@Override
public String fold(String current, Integer value) {
return current + "=" + value;
}
});
In Scala:
keyedInputStream.fold("Start")((str, i) => { str + "=" + i })
The preceding given function when applied on a stream of (1,2,3,4,5) would emit a stream like this: Start=1=2=3=4=5 复制代码