Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// ============================================================================
// 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.function;
import static java.util.Arrays.stream;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;
import functionalj.environments.Env;
import functionalj.functions.ThrowFuncs;
import functionalj.list.FuncList;
import functionalj.list.ImmutableList;
import functionalj.supportive.CallerId;
import functionalj.tuple.ImmutableTuple2;
import lombok.val;
@SuppressWarnings("javadoc")
public interface Func {
//== Provide different name for more readability ==
/**
* A shorter way to use Function.identity() -- alias for itself() and themAll().
*
* @param the type of it.
* @return the function that take it and return it.
**/
public static Func1 it() {
return it -> it;
}
/**
* A shorter way to use Function.identity() -- alias for it() and themAll().
*
* @param the type of it.
* @return the function that take it and return it.
**/
public static Func1 itself() {
return it -> it;
}
/**
* A shorter way to use Function.identity() -- alias for it() and itself().
*
* @param the type of it.
* @return the function that take it and return it.
**/
public static Func1 themAll() {
return it -> it;
}
public static Predicate alwaysTrue() {
return t -> true;
}
public static Predicate alwaysFalse() {
return t -> false;
}
/**
* A shorter way to do flatmap on list directly.
*
* @param the input data type.
* @param the output data type.
* @return the function that take list and change to stream.
*/
public static , OUT> Func1 super IN, Stream extends OUT>> allLists() {
return it -> it.stream();
}
/**
* A shorter way to do flatmap on list directly from the result of the given mapper function.
*
* @param the input data type.
* @param the output data type.
* @param mapper the mapper function.
* @return the function that will apply the given mapper functio to the input and change the result list to stream.
*/
public static Func1> allList(Func1> mapper) {
return it -> mapper.applyUnsafe(it).stream();
}
public static Predicate only(Function check) {
return input -> check.apply(input);
}
public static Predicate only(
Function mapper,
BiPredicate checker,
I2 tailInput) {
return i->checker.test(mapper.apply(i), tailInput);
}
//== List ==
@SafeVarargs
public static FuncList listOf(T ... data) {
return ImmutableList.of(data);
}
//== Of ==
/**
* Constructs a Func0 from supplier or lambda.
*
* @param supplier the supplier or lambda.
* @param