Package fj.data.optic

Class Fold<S,A>

java.lang.Object
fj.data.optic.Fold<S,A>
Type Parameters:
S - the source of a Fold
A - the target of a Fold

public abstract class Fold<S,A> extends Object
A Fold can be seen as a Getter with many targets or a weaker PTraversal which cannot modify its target. Fold is on the top of the Optic hierarchy which means that Getter, PTraversal, POptional, PLens, PPrism and PIso are valid Fold
  • Constructor Details

    • Fold

      public Fold()
  • Method Details

    • foldMap

      public abstract <M> F<S,M> foldMap(Monoid<M> m, F<A,M> f)
      map each target to a Monoid and combine the results underlying representation of Fold, all Fold methods are defined in terms of foldMap
    • fold

      public final F<S,A> fold(Monoid<A> m)
      combine all targets using a target's Monoid
    • getAll

      public final List<A> getAll(S s)
      get all the targets of a Fold TODO: Shall it return a Stream as there might be an infinite number of targets?
    • find

      public final F<S,Option<A>> find(F<A,Boolean> p)
      find the first target of a Fold matching the predicate
    • headOption

      public final Option<A> headOption(S s)
      get the first target of a Fold
    • exist

      public final F<S,Boolean> exist(F<A,Boolean> p)
      check if at least one target satisfies the predicate
    • all

      public final F<S,Boolean> all(F<A,Boolean> p)
      check if all targets satisfy the predicate
    • sum

      public final <S1> Fold<Either<S,S1>,A> sum(Fold<S1,A> other)
      join two Fold with the same target
    • composeFold

      public final <B> Fold<S,B> composeFold(Fold<A,B> other)
      compose a Fold with a Fold
    • composeGetter

      public final <C> Fold<S,C> composeGetter(Getter<A,C> other)
      compose a Fold with a Getter
    • composeOptional

      public final <B, C, D> Fold<S,C> composeOptional(POptional<A,B,C,D> other)
      compose a Fold with a POptional
    • composePrism

      public final <B, C, D> Fold<S,C> composePrism(PPrism<A,B,C,D> other)
      compose a Fold with a PPrism
    • composeLens

      public final <B, C, D> Fold<S,C> composeLens(PLens<A,B,C,D> other)
      compose a Fold with a PLens
    • composeIso

      public final <B, C, D> Fold<S,C> composeIso(PIso<A,B,C,D> other)
      compose a Fold with a PIso
    • id

      public static <A> Fold<A,A> id()
    • codiagonal

      public static <A> Fold<Either<A,A>,A> codiagonal()