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

jedi.either.Right Maven / Gradle / Ivy

The newest version!
package jedi.either;

import jedi.functional.Command;
import jedi.functional.Functor;

import java.util.Collections;
import java.util.List;

/**
 * Right typically represents a success value of Either - but not necessarily.
 */
public final class Right extends Either {

    public static final long serialVersionUID = 1L;

	private final B b;

	public Right(B b) {
		this.b = b;
	}

	@Override
	public boolean isRight() {
		return true;
	}

	@Override
	public  X fold(Functor fa, Functor fb) {
		return fb.execute(b);
	}

	@Override
	public void execute(Command ca, Command cb) {
		cb.execute(b);
	}

	@Override
	public Either swap() {
		return new Left(b);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == this) {
			return true;
		}
		if (obj == null || !getClass().equals(obj.getClass())) {
			return false;
		}
		Right other = (Right) obj;
		return b.equals(other.b);
	}

	@Override
	public int hashCode() {
		return b.hashCode();
	}

	@Override
	public String toString() {
		return "Right:" + b;
	}

	@Override
	public List asList() {
		return Collections.emptyList();
	}

	@Override
	public  Either map(Functor f) {
		return new Right(b);
	}

	@Override
	public  Either flatMap(Functor> f) {
		return new Right(b);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy