Skip to content

Commit c905d6c

Browse files
committed
re-arrange stream intro
1 parent 6ba7d2b commit c905d6c

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

chapter25-stream.jsh

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
// # Stream
66
// A stream is an API that defines a query on a source of values.
7-
// It's an abstraction of loops over the values using a declarative API
8-
// (what result you want and not how to compute it).
7+
// It's an abstraction of loops over values using a declarative API,
8+
// an API that describe the result you want and not how to compute it.
99

1010
// By example, to count the number of persons with a name starting by 'E',
1111
// one can write
@@ -24,6 +24,14 @@ var count = names.stream().filter(name -> name.startsWith("E")).count();
2424
System.out.println(count);
2525

2626

27+
// ### Why using streams instead of loops
28+
// The main reason is that it makes the code more readable,
29+
// obviously once you are used to read stream query,
30+
// - by allowing to easily compose operations
31+
// - by removing the declaration of intermediary local variables/states
32+
// (the variable `count` in the example above).
33+
34+
2735
// ## Sources
2836
// There are several ways to create a stream depending on the source
2937
// (The following examples are using `count()` to compute the number of values,

guide/chapter25-stream.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Stream
22
A stream is an API that defines a query on a source of values.
3-
It's an abstraction of loops over the values using a declarative API
4-
(what result you want and not how to compute it).
3+
It's an abstraction of loops over values using a declarative API,
4+
an API that describe the result you want and not how to compute it.
55

66
By example, to count the number of persons with a name starting by 'E',
77
one can write
@@ -24,6 +24,14 @@ System.out.println(count);
2424
```
2525

2626

27+
### Why using streams instead of loops
28+
The main reason is that it makes the code more readable,
29+
obviously once you are used to read stream query,
30+
- by allowing to easily compose operations
31+
- by removing the declaration of intermediary local variables/states
32+
(the variable `count` in the example above).
33+
34+
2735
## Sources
2836
There are several ways to create a stream depending on the source
2937
(The following examples are using `count()` to compute the number of values,

jupyter/chapter25-stream.ipynb

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [{
33
"cell_type": "markdown",
44
"metadata": {},
5-
"source": ["# Stream\n", "A stream is an API that defines a query on a source of values.\n", "It's an abstraction of loops over the values using a declarative API\n", "(what result you want and not how to compute it).\n"]
5+
"source": ["# Stream\n", "A stream is an API that defines a query on a source of values.\n", "It's an abstraction of loops over values using a declarative API,\n", "an API that describe the result you want and not how to compute it.\n"]
66
}
77
,
88
{
@@ -33,6 +33,12 @@
3333
"source": ["var names = List.of(\"Evan\", \"Helen\", \"Ebo\");\n", "var count = names.stream().filter(name -> name.startsWith(\"E\")).count();\n", "System.out.println(count);\n"]
3434
}
3535
,
36+
{
37+
"cell_type": "markdown",
38+
"metadata": {},
39+
"source": ["### Why using streams instead of loops\n", "The main reason is that it makes the code more readable,\n", "obviously once you are used to read stream query,\n", "- by allowing to easily compose operations\n", "- by removing the declaration of intermediary local variables/states\n", " (the variable `count` in the example above).\n"]
40+
}
41+
,
3642
{
3743
"cell_type": "markdown",
3844
"metadata": {},

0 commit comments

Comments
 (0)