All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.tonivade.purefun.Eq Maven / Gradle / Ivy

/*
 * Copyright (c) 2018-2020, Antonio Gabriel Muñoz Conejo 
 * Distributed under the terms of the MIT License
 */
package com.github.tonivade.purefun;

import java.util.Arrays;
import java.util.Objects;

/**
 * 

This interface represents a function that verify if two instances of a type are equivalent.

*

{@code Eq} instances can be composed using {@code and()} method

* @param type to verify */ @FunctionalInterface public interface Eq { boolean eqv(T a, T b); default Eq and(Eq other) { return (a, b) -> this.eqv(a, b) && other.eqv(a, b); } static Eq any() { return Objects::equals; } static Eq always() { return (a, b) -> true; } static Eq throwable() { return comparing(Throwable::getMessage).and(comparingArray(Throwable::getStackTrace)); } static Eq comparing(Function1 getter) { return (a, b) -> Objects.equals(getter.apply(a), getter.apply(b)); } static Eq comparingArray(Function1 getter) { return (a, b) -> Arrays.deepEquals(getter.apply(a), getter.apply(b)); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy