Class CollectionLens


  • public final class CollectionLens
    extends java.lang.Object
    Lenses that operate on Collections.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private CollectionLens()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <X,​CX extends java.util.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.
      static <X,​CX extends java.util.Collection<X>>
      Lens.Simple<CX,​java.util.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.
      static <X,​CX extends java.util.Collection<X>>
      Lens.Simple<CX,​java.util.stream.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CollectionLens

        private CollectionLens()
    • Method Detail

      • asCopy

        public static <X,​CX extends java.util.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 java.util.Collection<X>> Lens.Simple<CX,​java.util.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 java.util.Collection<X>> Lens.Simple<CX,​java.util.stream.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.