com.jnape.palatable.lambda.functor.builtin.Identity Maven / Gradle / Ivy
package com.jnape.palatable.lambda.functor.builtin;
import com.jnape.palatable.lambda.functor.Functor;
import java.util.function.Function;
/**
* A functor over some value of type A
that can be mapped over and retrieved later.
*
* @param the value type
*/
public final class Identity implements Functor {
private final A a;
public Identity(A a) {
this.a = a;
}
/**
* Retrieve the value.
*
* @return the value
*/
public A runIdentity() {
return a;
}
/**
* Covariantly map over the value.
*
* @param fn the mapping function
* @param the new value type
* @return an Identity over B (the new value)
*/
@Override
public Identity fmap(Function super A, ? extends B> fn) {
return new Identity<>(fn.apply(a));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy