functionalj.stream.StreamableAdditionalTerminalOperators Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionalj-core Show documentation
Show all versions of functionalj-core Show documentation
The module for FunctionalJ Core.
// ============================================================================
// Copyright (c) 2017-2019 Nawapunth Manusitthipol (NawaMan - http://nawaman.net).
// ----------------------------------------------------------------------------
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ============================================================================
package functionalj.stream;
import java.util.Comparator;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collector;
import functionalj.function.Func1;
import functionalj.list.FuncList;
import functionalj.map.FuncMap;
import functionalj.tuple.Tuple2;
public interface StreamableAdditionalTerminalOperators {
public StreamPlus stream();
//-- Functionalities --
public default void forEachWithIndex(
BiConsumer super Integer, ? super DATA> action) {
stream()
.forEachWithIndex(action);
}
//-- groupingBy --
// Eager
public default FuncMap> groupingBy(
Function super DATA, ? extends KEY> classifier) {
return stream()
.groupingBy(classifier);
}
// Eager
public default FuncMap groupingBy(
Function super DATA, ? extends KEY> classifier,
Function super FuncList, VALUE> aggregate) {
return stream()
.groupingBy(classifier, aggregate);
}
// Eager
public default FuncMap groupingBy(
Function super DATA, ? extends KEY> classifier,
StreamProcessor super DATA, VALUE> processor) {
return stream()
.groupingBy(classifier, processor);
}
// Eager
public default FuncMap groupingBy(
Function super DATA, ? extends KEY> classifier,
Supplier> collectorSupplier) {
return stream()
.groupingBy(classifier, collectorSupplier);
}
//-- min-max --
public default > Optional minBy(
Func1 mapper) {
return stream()
.minBy(mapper);
}
public default > Optional maxBy(
Func1 mapper) {
return stream()
.maxBy(mapper);
}
public default Optional minBy(
Func1 mapper,
Comparator super D> comparator) {
return stream()
.minBy(mapper, comparator);
}
public default Optional maxBy(
Func1 mapper,
Comparator super D> comparator) {
return stream()
.maxBy(mapper, comparator);
}
public default Tuple2, Optional> minMax(
Comparator super DATA> comparator) {
return stream()
.minMax(comparator);
}
public default > Tuple2, Optional> minMaxBy(
Func1 mapper) {
return stream()
.minMaxBy(mapper);
}
public default Tuple2, Optional> minMaxBy(
Func1 mapper,
Comparator super D> comparator) {
return stream()
.minMaxBy(mapper, comparator);
}
//-- Find --
public default Optional findFirst(
Function super DATA, T> mapper,
Predicate super T> theCondition) {
return stream()
.findFirst(mapper, theCondition);
}
public default Optional findAny(
Function super DATA, T> mapper,
Predicate super T> theCondition) {
return stream()
.findAny(mapper, theCondition);
}
public default Optional findFirst(
Predicate super DATA> predicate) {
return stream()
.findFirst(predicate);
}
public default Optional findAny(
Predicate super DATA> predicate) {
return stream()
.findAny(predicate);
}
//-- toMap --
public default FuncMap toMap(
Function super DATA, ? extends KEY> keyMapper) {
return stream()
.toMap(keyMapper);
}
public default FuncMap toMap(
Function super DATA, ? extends KEY> keyMapper,
Function super DATA, ? extends VALUE> valueMapper) {
return stream()
.toMap(keyMapper, valueMapper);
}
public default FuncMap toMap(
Function super DATA, ? extends KEY> keyMapper,
Function super DATA, ? extends VALUE> valueMapper,
BinaryOperator mergeFunction) {
return stream()
.toMap(keyMapper, valueMapper, mergeFunction);
}
public default FuncMap toMap(
Function super DATA, ? extends KEY> keyMapper,
BinaryOperator mergeFunction) {
return stream()
.toMap(keyMapper, mergeFunction);
}
}