Skip to content

Commit

Permalink
Remove min/max
Browse files Browse the repository at this point in the history
  • Loading branch information
tginsberg committed Jan 5, 2025
1 parent 48a5c94 commit ba6553c
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 362 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
+ Implement `movingProduct()` and `movingProductBy()`
+ Implement `movingSum()` and `movingSumBy()`
+ Functions, when used as arguments, should come last for consistency and to play nice with Kotlin (Fixes #64)
+ Remove `maxBy(fn)` and `minBy(fn)`, can be done with JDK methods trivially

### 0.6.0
+ Implement `dropLast(n)`
Expand Down
27 changes: 0 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ implementation("com.ginsberg:gatherers4j:0.7.0")
| `interleave(iterator)` | Creates a stream of alternating objects from the input stream and the argument iterator |
| `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 |
| `maxBy(fn)` | Return a stream containing a single element, which is the maximum value returned by the mapping function `fn` |
| `minBy(fn)` | Return a stream containing a single element, which is the minimum value returned by the mapping function `fn` |
| `orderByFrequencyAscending() | Returns a stream where elements are ordered from least to most frequent as `WithCount<T>` wrapper objects. |
| `orderByFrequencyDescending() | Returns a stream where elements are ordered from most to least frequent as `WithCount<T>` wrapper objects. |
| `reverse()` | Reverse the order of the stream |
Expand Down Expand Up @@ -228,31 +226,6 @@ Stream
// ["E", "F", "G"]
```

#### Find the object with the maximum mapped value

```java
record Employee(String name, int salary) {}

streamOfEmployees
.gather(Gatherers4j.maxBy(Employee:salary))
.toList();

// Employee("Big Shot", 1_000_000)
```

#### Find the object with the minimum mapped value

```java
record Person(String name, int age) {}

streamOfPeople
.gather(Gatherers4j.minBy(Person:age))
.toList();

// Person("Baby", 1)
```


#### Order elements by frequency, ascending

```java
Expand Down
30 changes: 0 additions & 30 deletions src/main/java/com/ginsberg/gatherers4j/Gatherers4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,36 +167,6 @@ public static <INPUT> LastGatherer<INPUT> last(final int count) {
return new LastGatherer<>(count);
}

/// Return a Stream containing the single maximum value of the input stream, according to
/// the given mapping function. In the case where a stream has more than one mapped value
/// that is the maximum, the first one encountered makes up the stream. This does not
/// evaluate null values or null mappings.
///
/// @param mappingFunction A mapping function, the results of which must implement `Comparable`
/// @param <INPUT> Type of elements in the input stream
/// @param <MAPPED> Type of object returned from the `mappingFunction`, which much implement `Comparable`
/// @return A non-null `MinMaxGatherer`
public static <INPUT extends @Nullable Object, MAPPED extends @Nullable Comparable<MAPPED>> MinMaxGatherer<INPUT, MAPPED> maxBy(
final Function<INPUT, MAPPED> mappingFunction
) {
return new MinMaxGatherer<>(true, mappingFunction);
}

/// Return a Stream containing the single minimum value of the input stream, according to
/// the given mapping function. In the case where a stream has more than one mapped value
/// that is the minimum, the first one encountered makes up the stream. This does not
/// evaluate null values or null mappings.
///
/// @param mappingFunction A mapping function, the results of which must implement `Comparable`
/// @param <INPUT> Type of elements in the input stream
/// @param <MAPPED> Type of object returned from the `mappingFunction`, which much implement `Comparable`
/// @return A non-null `MinMaxGatherer`
public static <INPUT extends @Nullable Object, MAPPED extends @Nullable Comparable<MAPPED>> MinMaxGatherer<INPUT, MAPPED> minBy(
final Function<INPUT, MAPPED> mappingFunction
) {
return new MinMaxGatherer<>(false, mappingFunction);
}

/// Create a Stream that represents the moving product of a `Stream<BigDecimal>` looking
/// back `windowSize` number of elements.
///
Expand Down
80 changes: 0 additions & 80 deletions src/main/java/com/ginsberg/gatherers4j/MinMaxGatherer.java

This file was deleted.

225 changes: 0 additions & 225 deletions src/test/java/com/ginsberg/gatherers4j/MinMaxGathererTest.java

This file was deleted.

0 comments on commit ba6553c

Please sign in to comment.