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

com.jnape.palatable.lambda.monoid.builtin.Xor 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.functions.Fn1;
import com.jnape.palatable.lambda.functions.specialized.BiPredicate;
import com.jnape.palatable.lambda.monoid.Monoid;

/**
 * Logical exclusive-or. Equivalent to logical ^.
 * 

* Note that this implementation behaves as a cascade of binary exclusive-or operations, as is the only possible * monoidal behavior when applied to an unknown number of inputs. * * @see Or * @see And */ public class Xor implements Monoid, BiPredicate { private static final Xor INSTANCE = new Xor(); private Xor() { } @Override public Boolean identity() { return false; } @Override public Boolean apply(Boolean x, Boolean y) { return x ^ y; } @Override public boolean test(Boolean x, Boolean y) { return apply(x, y); } @Override public Xor flip() { return this; } public static Xor xor() { return INSTANCE; } public static Fn1 xor(Boolean x) { return xor().apply(x); } public static Boolean xor(Boolean x, Boolean y) { return xor(x).apply(y); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy