
javaslang.algebra.Semigroup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javaslang-algebra Show documentation
Show all versions of javaslang-algebra Show documentation
An algebraic layer for javaslang.r
The newest version!
/* / \____ _ _ ____ ______ / \ ____ __ _ _____
* / / \/ \ / \/ \ / /\__\/ // \/ \ / / _ \ Javaslang
* _/ / /\ \ \/ / /\ \\__\\ \ // /\ \ /\\/ \__/ / Copyright 2014-now Daniel Dietrich
* /___/\_/ \_/\____/\_/ \_/\__\/__/___\_/ \_// \__/_____/ Licensed under the Apache License, Version 2.0
*/
package javaslang.algebra;
/**
* A Semigroup is a type with an associative binary operation {@linkplain #combine(Object, Object)}.
* Given a type {@code A}, instances of Semigroup should satisfy the following law:
*
* - Associativity: {@code combine(combine(x,y),z) == combine(x,combine(y,z))} for any {@code x,y,z} of type
* {@code A}.
*
* Note: Technically a Semigroup is the same as a {@code java.util.function.BiFunction}. Introducing this new type
* clarifies that the operation {@code combine} is associative.
*
* @param A type.
* @author Daniel Dietrich
* @since 1.1.0
*/
@FunctionalInterface
public interface Semigroup {
/**
* Combines two elements of the same type, which is also returned.
*
* @param a1 An element
* @param a2 Another element
* @return The combination of a1 and a2
*/
A combine(A a1, A a2);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy