fj.data.optic.Lens Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionaljava Show documentation
Show all versions of functionaljava Show documentation
Functional Java is an open source library that supports closures for the Java programming language
package fj.data.optic;
import fj.F;
import fj.P1;
import fj.control.Trampoline;
import fj.control.parallel.Promise;
import fj.data.Either;
import fj.data.IO;
import fj.data.List;
import fj.data.Option;
import fj.data.Stream;
import fj.data.Validation;
import fj.data.vector.V2;
/**
* {@link PLens} with a monomorphic set function
*/
public final class Lens extends PLens {
final PLens pLens;
public Lens(final PLens pLens) {
this.pLens = pLens;
}
@Override
public A get(final S s) {
return pLens.get(s);
}
@Override
public F set(final A a) {
return pLens.set(a);
}
@Override
public F> modifyFunctionF(final F> f) {
return pLens.modifyFunctionF(f);
}
@Override
public F> modifyEitherF(final F> f) {
return pLens.modifyEitherF(f);
}
@Override
public F> modifyIOF(final F> f) {
return pLens.modifyIOF(f);
}
@Override
public F> modifyTrampolineF(final F> f) {
return pLens.modifyTrampolineF(f);
}
@Override
public F> modifyPromiseF(final F> f) {
return pLens.modifyPromiseF(f);
}
@Override
public F> modifyListF(final F> f) {
return pLens.modifyListF(f);
}
@Override
public F> modifyOptionF(final F> f) {
return pLens.modifyOptionF(f);
}
@Override
public F> modifyStreamF(final F> f) {
return pLens.modifyStreamF(f);
}
@Override
public F> modifyP1F(final F> f) {
return pLens.modifyP1F(f);
}
@Override
public F> modifyValidationF(final F> f) {
return pLens.modifyValidationF(f);
}
@Override
public F> modifyV2F(final F> f) {
return pLens.modifyV2F(f);
}
@Override
public F modify(final F f) {
return pLens.modify(f);
}
/** join two {@link Lens} with the same target */
public final Lens, A> sum(final Lens other) {
return new Lens<>(pLens.sum(other.pLens));
}
/**********************************************************/
/** Compose methods between a {@link Lens} and another Optics */
/**********************************************************/
/**
* compose a {@link Lens} with a {@link Setter}
*/
public final Setter composeSetter(final Setter other) {
return new Setter<>(pLens.composeSetter(other.pSetter));
}
/**
* compose a {@link Lens} with a {@link Traversal}
*/
public final Traversal composeTraversal(final Traversal other) {
return new Traversal<>(pLens.composeTraversal(other.pTraversal));
}
/** compose a {@link Lens} with an {@link Optional} */
public final Optional composeOptional(final Optional other) {
return new Optional<>(pLens.composeOptional(other.pOptional));
}
/** compose a {@link Lens} with a {@link Prism} */
public final Optional composePrism(final Prism other) {
return new Optional<>(pLens.composePrism(other.pPrism));
}
/** compose a {@link Lens} with a {@link Lens} */
public final Lens composeLens(final Lens other) {
return new Lens<>(pLens.composeLens(other.pLens));
}
/** compose a {@link Lens} with an {@link Iso} */
public final Lens composeIso(final Iso other) {
return new Lens<>(pLens.composeIso(other.pIso));
}
/****************************************************************/
/** Transformation methods to view a {@link Lens} as another Optics */
/****************************************************************/
/** view a {@link Lens} as a {@link Setter} */
@Override
public Setter asSetter() {
return new Setter<>(pLens.asSetter());
}
/** view a {@link Lens} as a {@link Traversal} */
@Override
public final Traversal asTraversal() {
return new Traversal<>(pLens.asTraversal());
}
/** view a {@link Lens} as an {@link Optional} */
@Override
public final Optional asOptional() {
return new Optional<>(pLens.asOptional());
}
public static final Lens id() {
return new Lens<>(PLens.pId());
}
/**
* create a {@link Lens} using a pair of functions: one to get the target, one to set the target.
*/
public static Lens lens(final F get, final F> set) {
return new Lens<>(PLens.pLens(get, set));
}
}