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

com.shapesecurity.functional.data.FreePairingMonoid Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
package com.shapesecurity.functional.data;

import com.shapesecurity.functional.Pair;

import javax.annotation.Nonnull;

public final class FreePairingMonoid implements Monoid> {
    @Nonnull
    private final Monoid monoidA;
    @Nonnull
    private final Monoid monoidB;

    public FreePairingMonoid(@Nonnull Monoid monoidA, @Nonnull Monoid monoidB) {
        this.monoidA = monoidA;
        this.monoidB = monoidB;
    }

    @Nonnull
    @Override
    public Pair identity() {
        return new Pair<>(this.monoidA.identity(), this.monoidB.identity());
    }

    @Nonnull
    @Override
    public Pair append(Pair a, Pair b) {
        return new Pair<>(this.monoidA.append(a.left, b.left), this.monoidB.append(a.right, b.right));
    }
}