Class CollectionLens
java.lang.Object
com.jnape.palatable.lambda.optics.lenses.CollectionLens
Lenses that operate on
Collection
s.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <X,
CX extends Collection<X>>
Lens.Simple<CX, CX> 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 Collection<X>>
Lens.Simple<CX, Set<X>> Convenience static factory method for creating a lens that focuses on an arbitraryCollection
as aSet
.static <X,
CX extends Collection<X>>
Lens.Simple<CX, Stream<X>> Convenience static factory method for creating a lens that focuses on a Collection as a Stream.
-
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 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 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 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 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 typeCX
- the type of the collection- Parameters:
copyFn
- the copying function- Returns:
- a lens that focuses on a Collection as a stream.
-