Skip to content

Commit

Permalink
Documentation update for shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
tginsberg committed Sep 24, 2024
1 parent a01dc8a commit d6e3966
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
50 changes: 37 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ implementation("com.ginsberg:gatherers4j:0.4.0")
# Gatherers In This Library

### Streams
| Function | Purpose |
|------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| Function | Purpose |
|------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| `debounce(amount, duration)` | Limit stream elements to `amount` elements over `duration`, dropping any elements over the limit until a new `duration` starts |
| `dedupeConsecutive()` | Remove consecutive duplicates from a stream |
| `dedupeConsecutiveBy(fn)` | Remove consecutive duplicates from a stream as returned by `fn` |
| `distinctBy(fn)` | Emit only distinct elements from the stream, as measured by `fn` |
| `interleave(stream)` | Creates a stream of alternating objects from the input stream and the argument stream |
| `last(n)` | Constrain the stream to the last `n` values |
| `throttle(amount, duration)` | Limit stream elements to `amount` elements over `duration`, pausing until a new `duration` period starts |
| `withIndex()` | Maps all elements of the stream as-is along with their 0-based index |
| `withIndexStartingAt(n)` | Maps all elements of the stream as-is along with an index starting at the number specified |
| `zipWith(stream)` | Creates a stream of `Pair` objects whose values come from the input stream and argument stream |
| `zipWithNext()` | Creates a stream of `List` objects via a sliding window of width 2 and stepping 1 |
| `dedupeConsecutive()` | Remove consecutive duplicates from a stream |
| `dedupeConsecutiveBy(fn)` | Remove consecutive duplicates from a stream as returned by `fn` |
| `distinctBy(fn)` | Emit only distinct elements from the stream, as measured by `fn` |
| `interleave(stream)` | Creates a stream of alternating objects from the input stream and the argument stream |
| `last(n)` | Constrain the stream to the last `n` values |
| `shuffle()` | Shuffle the stream into a random order using the platform default `RandomGenerator` |
| `shuffle(rg)` | Shuffle the stream into a random order using the specified `RandomGenerator` |
| `throttle(amount, duration)` | Limit stream elements to `amount` elements over `duration`, pausing until a new `duration` period starts |
| `withIndex()` | Maps all elements of the stream as-is along with their 0-based index |
| `withIndexStartingAt(n)` | Maps all elements of the stream as-is along with an index starting at the number specified |
| `zipWith(stream)` | Creates a stream of `Pair` objects whose values come from the input stream and argument stream |
| `zipWithNext()` | Creates a stream of `List` objects via a sliding window of width 2 and stepping 1 |

### Mathematics/Statistics
| Function | Purpose |
Expand Down Expand Up @@ -160,7 +162,29 @@ Stream
// [IndexedValue(0, "A"), IndexedValue(1, "B"), IndexedValue(2, "C")]
```

### Throttle the number of elements consumed in a period
#### Shuffle the stream into a random order

```java
Stream
.of("A", "B", "C", "D" ,"E")
.gather(Gatherers4j.shuffle())
.toList();

// ex: ["B", "E", "A", "C", "D"] -- or some other randomly arranged stream
```

#### Shuffle the stream into a random order, with a specific `RandomGenerator`

```java
Stream
.of("A", "B", "C", "D" ,"E")
.gather(Gatherers4j.shuffle(RandomGenerator.of("someGenerator")))
.toList();

// ex: ["B", "E", "A", "C", "D"] -- or some other randomly arranged stream
```

#### Throttle the number of elements consumed in a period

```java
Stream
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ginsberg/gatherers4j/Gatherers4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.time.Duration;
import java.util.List;
import java.util.function.Function;
import java.util.random.RandomGenerator;
import java.util.random.RandomGeneratorFactory;
import java.util.stream.Gatherer;
import java.util.stream.Stream;

Expand Down

0 comments on commit d6e3966

Please sign in to comment.