Skip to content

Commit 481f836

Browse files
committed
Adding more examples to README.md
1 parent aac49f9 commit 481f836

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ And has support for...
3131
+ Exclusive end point (`until`)
3232
+ Configurable period between stream elements (`every`)
3333
+ Streams can move forward or backward through time
34+
+ Infinite streams (by not providing an end point)
3435

3536
## Usage
3637

@@ -40,11 +41,19 @@ builder can be created using one of two methods:
4041
+ `.fromNow()` - Assumes 'now'
4142
+ `.from(T from)` - Type-specific starting point, provided by caller
4243

43-
To set the point in time where the stream ends (optional!), you can call one of two methods:
44+
To set the optional point in time where the stream ends (inclusive) you can call one of two methods:
4445

4546
+ `.to(T to)` - Type-specific end point. Can be null to indicate forever
4647
+ `.to(amount, units)` - Where `amount` is a positive integer (for forward through time) or a negative integer (for backward through time), and `unit` is a valid `ChronoUnit`
4748

49+
To make the optional end of the stream exclusive, you can call one of two methods:
50+
51+
+ `.until(T to)` - Type-specific end point. Can be null to indicate forever
52+
+ `.until(amount, units)` - Where `amount` is a positive integer (for forward through time) or a negative integer (for backward through time), and `unit` is a valid `ChronoUnit`
53+
54+
Note that providing an end time (via `to` or `until`) is optional. In that case, the stream will
55+
have no end and should produce values until you stop it.
56+
4857
## Examples
4958

5059
Create a stream of `LocalDateTime` objects, between now and hour from now, every two minutes:
@@ -78,6 +87,31 @@ final Stream<YearMonth> stream = YearMonthStream
7887
.stream();
7988
```
8089

90+
Replace this code that does something with every minute of time over the last hour, going backwards:
91+
92+
```java
93+
final LocalDateTime end = LocalDateTime.now().minusHours(1);
94+
LocalDateTime when = LocalDateTime.now();
95+
96+
while(when.isAfter(end)) {
97+
doSomething(when);
98+
when = when.minusMinutes(1);
99+
}
100+
```
101+
102+
... with this:
103+
104+
```java
105+
LocalDateTimeStream
106+
.fromNow()
107+
.until(LocalDateTime.now().minusHours(1))
108+
.every(1, ChronoUnit.MINUTES)
109+
.stream()
110+
.forEach(this::doSomething);
111+
```
112+
113+
It's not less code, but it certainly makes it easier to understand.
114+
81115
There are also plenty of examples in the unit tests.
82116

83117
## Contributing and Issues

0 commit comments

Comments
 (0)