Repository: flink
Updated Branches:
  refs/heads/master 38cf0c610 -> 2f013a204


[hotfix] [docs] Fix errors in streaming docs for fold()


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/2f013a20
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/2f013a20
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/2f013a20

Branch: refs/heads/master
Commit: 2f013a20414a825bb6fc31dfc96ff562141e209b
Parents: 38cf0c6
Author: Stephan Ewen <se...@apache.org>
Authored: Thu Nov 19 20:33:17 2015 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Thu Nov 19 20:33:17 2015 +0100

----------------------------------------------------------------------
 docs/apis/streaming_guide.md | 48 +++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/2f013a20/docs/apis/streaming_guide.md
----------------------------------------------------------------------
diff --git a/docs/apis/streaming_guide.md b/docs/apis/streaming_guide.md
index fb6d86a..db1f3a7 100644
--- a/docs/apis/streaming_guide.md
+++ b/docs/apis/streaming_guide.md
@@ -519,22 +519,23 @@ keyedStream.reduce(new ReduceFunction<Integer>() {
           </td>
         </tr>
         <tr>
-          <td><strong>Fold</strong><br>DataStream &rarr; DataStream</td>
+          <td><strong>Fold</strong><br>KeyedStream &rarr; DataStream</td>
           <td>
           <p>A "rolling" fold on a keyed data stream with an initial value. 
           Combines the current element with the last folded value and
           emits the new value.
           <br/>
           <br/>
-          A fold function that creates a stream of partial sums:</p>
+          <p>A fold function that, when applied on the sequence (1,2,3,4,5), 
+          emits the sequence "start-1", "start-1-2", "start-1-2-3", ...</p>
           {% highlight java %}
-keyedStream.fold(0, new ReduceFunction<Integer>() {
-  @Override
-  public Integer fold(Integer accumulator, Integer value)
-  throws Exception {
-      return accumulator + value;
-  }
-});
+DataStream<String> result = 
+  keyedStream.fold("start", new FoldFunction<Integer, String>() {
+    @Override
+    public String fold(String current, Integer value) {
+        return current + "-" + value;
+    }
+  });
           {% endhighlight %}
           </p>
           </td>
@@ -621,11 +622,13 @@ windowedStream.reduce (new 
ReduceFunction<Tuple2<String,Integer>() {
         <tr>
           <td><strong>Window Fold</strong><br>WindowedStream &rarr; 
DataStream</td>
           <td>
-            <p>Applies a functional fold function to the window and returns 
the folded value.</p>
+            <p>Applies a functional fold function to the window and returns 
the folded value.
+               The example function, when applied on the sequence (1,2,3,4,5),
+               folds the sequence into the string "start-1-2-3-4-5":</p>
     {% highlight java %}
-windowedStream.fold (new Tuple2<String,Integer>("Sum of all", 0),  new 
FoldFunction<Tuple2<String,Integer>() {
-    public Tuple2<String, Integer> fold(Tuple2<String, Integer> acc, 
Tuple2<String, Integer> value) throws Exception {
-        return new Tuple2<String,Integer>(acc.f0, acc.f1 + value.f1);
+windowedStream.fold("start-", new FoldFunction<Integer, String>() {
+    public String fold(String current, Integer value) {
+        return current + "-" + value;
     }
 };
     {% endhighlight %}
@@ -884,16 +887,18 @@ keyedStream.reduce { _ + _ }
           </td>
         </tr>
         <tr>
-          <td><strong>Fold</strong><br>DataStream &rarr; DataStream</td>
+          <td><strong>Fold</strong><br>KeyedStream &rarr; DataStream</td>
           <td>
           <p>A "rolling" fold on a keyed data stream with an initial value.
           Combines the current element with the last folded value and
           emits the new value.
           <br/>
           <br/>
-          A fold function that creates a stream of partial sums:</p>
+          <p>A fold function that, when applied on the sequence (1,2,3,4,5),
+          emits the sequence "start-1", "start-1-2", "start-1-2-3", ...</p>
           {% highlight scala %}
-keyedStream.fold { 0, _ + _ }
+val result: DataStream[String] = 
+    keyedStream.fold("start", (str, i) => { str + "-" + i })
           {% endhighlight %}
           </p>
           </td>
@@ -965,10 +970,13 @@ windowedStream.reduce { _ + _ }
         <tr>
           <td><strong>Window Fold</strong><br>WindowedStream &rarr; 
DataStream</td>
           <td>
-            <p>Applies a functional fold function to the window and returns 
the folded value.</p>
-    {% highlight java %}
-windowedStream.fold { 0, _ + _ }
-    {% endhighlight %}
+            <p>Applies a functional fold function to the window and returns 
the folded value.
+               The example function, when applied on the sequence (1,2,3,4,5),
+               folds the sequence into the string "start-1-2-3-4-5":</p>
+          {% highlight scala %}
+val result: DataStream[String] = 
+    windowedStream.fold("start", (str, i) => { str + "-" + i })
+          {% endhighlight %}
           </td>
        </tr>
         <tr>

Reply via email to