Skip to content

Commit

Permalink
introduce Streams.or()
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Jul 16, 2024
1 parent 167b148 commit d99cfb8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/comroid/api/func/util/Streams.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ public static <T> Collector<T, List<T>, Stream<T>> atLeastOneOrElseFlatten(Suppl
}, ls -> ls.isEmpty() ? otherwise.get() : ls.stream());
}

public static <T> Collector<T, List<T>, Stream<T>> or(Supplier<Stream<T>> supplier) {
return Collector.of(ArrayList::new, Collection::add, (l, r) -> {
l.addAll(r);
return l;
}, ls -> {
if (ls.isEmpty())
return supplier.get();
return ls.stream();
});
}

@Deprecated(forRemoval = true)
public static <T, C> Comparator<T> comparatorAdapter(final @NotNull Function<T, C> mapper, final @NotNull Comparator<C> comparator) {
return (a, b) -> comparator.compare(mapper.apply(a), mapper.apply(b));
Expand Down

0 comments on commit d99cfb8

Please sign in to comment.