You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: collection-pipeline/README.md
+128-8Lines changed: 128 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -3,25 +3,145 @@ title: Collection Pipeline
3
3
category: Functional
4
4
language: en
5
5
tag:
6
-
- Reactive
6
+
- Reactive
7
+
- Data processing
7
8
---
8
9
9
10
## Intent
10
-
Collection Pipeline introduces Function Composition and Collection Pipeline, two functional-style patterns that you can combine to iterate collections in your code.
11
-
In functional programming, it's common to sequence complex operations through a series of smaller modular functions or operations. The series is called a composition of functions, or a function composition. When a collection of data flows through a function composition, it becomes a collection pipeline. Function Composition and Collection Pipeline are two design patterns frequently used in functional-style programming.
11
+
12
+
The Collection Pipeline design pattern is intended to process collections of data by chaining together operations in a
13
+
sequence where the output of one operation is the input for the next. It promotes a declarative approach to handling
14
+
collections, focusing on what should be done rather than how.
15
+
16
+
## Explanation
17
+
18
+
Real-world example
19
+
20
+
> Imagine you're in a large library filled with books, and you're tasked with finding all the science fiction books
21
+
> published after 2000, then arranging them by author name in alphabetical order, and finally picking out the top 5 based
22
+
> on their popularity or ratings.
23
+
24
+
In plain words
25
+
26
+
> The Collection Pipeline pattern involves processing data by passing it through a series of operations, each
27
+
> transforming the data in sequence, much like an assembly line in a factory.
28
+
29
+
Wikipedia says
30
+
31
+
> In software engineering, a pipeline consists of a chain of processing elements (processes, threads, coroutines,
32
+
> functions, etc.), arranged so that the output of each element is the input of the next; the name is by analogy to a
33
+
> physical pipeline. Usually some amount of buffering is provided between consecutive elements. The information that flows
34
+
> in these pipelines is often a stream of records, bytes, or bits, and the elements of a pipeline may be called filters;
35
+
> this is also called the pipe(s) and filters design pattern. Connecting elements into a pipeline is analogous to function
36
+
> composition.
37
+
38
+
**Programmatic Example**
39
+
40
+
The Collection Pipeline pattern is implemented in this code example by using Java's Stream API to perform a series of
41
+
transformations on a collection of Car objects. The transformations are chained together to form a pipeline. Here's a
42
+
breakdown of how it's done:
43
+
44
+
1. Creation of Cars: A list of Car objects is created using the `CarFactory.createCars()` method.
45
+
46
+
`var cars = CarFactory.createCars();`
47
+
48
+
2. Filtering and Transforming: The `FunctionalProgramming.getModelsAfter2000(cars)` method filters the cars to only
49
+
include those made after the year 2000, and then transforms the filtered cars into a list of their model names.
0 commit comments