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

com.jnape.palatable.lambda.monoid.builtin.Merge 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.BiMonoidFactory;
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#merge}, a semigroup over L, and a monoid over
 * R. Like {@link Either#merge}, this is left-biased.
 * 

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy