Class CollectionLens
- java.lang.Object
-
- com.jnape.palatable.lambda.optics.lenses.CollectionLens
-
public final class CollectionLens extends java.lang.Object
Lenses that operate onCollection
s.
-
-
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 aCollection
, 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 arbitraryCollection
as aSet
.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.
-
-
-
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 aCollection
, given a function that creates the copy. Useful for composition to avoid mutating aCollection
reference.- Type Parameters:
X
- the collection element typeCX
- 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 arbitraryCollection
as aSet
.- Type Parameters:
X
- the collection element typeCX
- 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 typeCX
- the type of the collection- Parameters:
copyFn
- the copying function- Returns:
- a lens that focuses on a Collection as a stream.
-
-