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

com.jnape.palatable.lambda.monoid.builtin.RightAny Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
package com.jnape.palatable.lambda.monoid.builtin;

import com.jnape.palatable.lambda.adt.Either;
import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functions.specialized.MonoidFactory;
import com.jnape.palatable.lambda.monoid.Monoid;
import com.jnape.palatable.lambda.semigroup.Semigroup;

import static com.jnape.palatable.lambda.adt.Either.right;

/**
 * A {@link Monoid} instance formed by {@link Either}<L,R> and a monoid over R. The
 * application to two {@link Either} values is right-biased, such that for a given {@link Either} x and
 * y:
 * 
    *
  • if both x and y are right values, the result is the application of the x and y values * in terms of the provided monoid, wrapped in {@link Either#right}
  • *
  • if only x is a right value, the result is x
  • *
  • if only y is a right value, the result is y
  • *
  • if neither x nor y are right values, the result is y
  • *
*

* For the {@link Semigroup}, see {@link com.jnape.palatable.lambda.semigroup.builtin.RightAny}. * * @param The left parameter type * @param The right parameter type * @see Monoid * @see Either */ public final class RightAny implements MonoidFactory, Either> { private static final RightAny INSTANCE = new RightAny(); private RightAny() { } @Override public Monoid> apply(Monoid rMonoid) { Semigroup> semigroup = com.jnape.palatable.lambda.semigroup.builtin.RightAny.rightAny(rMonoid); return Monoid.>monoid(semigroup, () -> right(rMonoid.identity())); } @SuppressWarnings("unchecked") public static RightAny rightAny() { return INSTANCE; } public static Semigroup> rightAny(Monoid rMonoid) { return RightAny.rightAny().apply(rMonoid); } public static Fn1, Either> rightAny(Monoid rMonoid, Either x) { return RightAny.rightAny(rMonoid).apply(x); } public static Either rightAny(Monoid rMonoid, Either x, Either y) { return rightAny(rMonoid, x).apply(y); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy