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 org.jetbrains.annotations.NotNull;

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

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

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

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