Class CollectionLens

java.lang.Object
com.jnape.palatable.lambda.optics.lenses.CollectionLens

public final class CollectionLens extends Object
Lenses that operate on Collections.
  • Constructor Details

    • CollectionLens

      private CollectionLens()
  • Method Details

    • asCopy

      public static <X, CX extends Collection<X>> Lens.Simple<CX,CX> asCopy(Fn1<? super CX,? extends CX> copyFn)
      Convenience static factory method for creating a lens that focuses on a copy of a Collection, given a function that creates the copy. Useful for composition to avoid mutating a Collection reference.
      Type Parameters:
      X - the collection element type
      CX - the type of the collection
      Parameters:
      copyFn - the copying function
      Returns:
      a lens that focuses on a copy of CX
    • asSet

      public static <X, CX extends Collection<X>> Lens.Simple<CX,Set<X>> asSet(Fn1<? super CX,? extends CX> copyFn)
      Convenience static factory method for creating a lens that focuses on an arbitrary Collection as a Set.
      Type Parameters:
      X - the collection element type
      CX - the type of the collection
      Parameters:
      copyFn - the copying function
      Returns:
      a lens that focuses on a Collection as a Set
    • asStream

      public static <X, CX extends Collection<X>> Lens.Simple<CX,Stream<X>> asStream(Fn1<? super CX,? extends CX> copyFn)
      Convenience static factory method for creating a lens that focuses on a Collection as a Stream.

      Note that this lens is effectively lawful, though difficult to prove given the intrinsically stateful and inequitable nature of Stream.

      Type Parameters:
      X - the collection element type
      CX - the type of the collection
      Parameters:
      copyFn - the copying function
      Returns:
      a lens that focuses on a Collection as a stream.