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

fj.data.optic.Setter Maven / Gradle / Ivy

Go to download

Functional Java is an open source library that supports closures for the Java programming language

There is a newer version: 5.0
Show newest version
package fj.data.optic;

import fj.F;
import fj.data.Either;

/** {@link PSetter} with a monomorphic modify function */
public final class Setter extends PSetter {

  final PSetter pSetter;

  public Setter(final PSetter pSetter) {
    this.pSetter = pSetter;
  }

  @Override
  public F modify(final F f) {
    return pSetter.modify(f);
  }

  @Override
  public F set(final A b) {
    return pSetter.set(b);
  }

  /** join two {@link Setter} with the same target */
  public  Setter, A> sum(final Setter other) {
    return new Setter<>(pSetter.sum(other.pSetter));
  }

  /************************************************************/
  /** Compose methods between a {@link Setter} and another Optics */
  /************************************************************/

  /** compose a {@link Setter} with a {@link Setter} */
  public  Setter composeSetter(final Setter other) {
    return new Setter<>(pSetter.composeSetter(other.pSetter));
  }

  /** compose a {@link Setter} with a {@link Traversal} */
  public  Setter composeTraversal(final Traversal other) {
    return new Setter<>(pSetter.composeTraversal(other.pTraversal));
  }

  /** compose a {@link Setter} with an {@link Iso} */
  public  Setter composeIso(final Iso other) {
    return new Setter<>(pSetter.composeIso(other.pIso));
  }

  public static  Setter id() {
    return new Setter<>(PSetter.pId());
  }

  public static  Setter, S> codiagonal() {
    return new Setter<>(PSetter.pCodiagonal());
  }

  /** alias for {@link PSetter} constructor with a monomorphic modify function */
  public static  Setter setter(final F, F> modify) {
    return new Setter<>(PSetter.pSetter(modify));
  }
}