PLens
public class PLens<S, T, A, B>
A Lens (or Functional Reference) is an optic that can focus into a structure for getting, setting or modifying the focus (target).
A (polymorphic) PLens is useful when setting or modifying a value for a constructed type.
A PLens can be seen as a pair of functions:
- get: (S) -> A meaning we can focus into S and extract an A.
- set: (B, S) -> T meaning we can focus into an S and set a value B for a target A and obtain a modified source.
The type arguments are:
- S is the source of a PLens.
- T is the modified source of a PLens.
- A is the focus of a PLens.
- B is the modified focus of a PLens.
-
Composes a
PLenswith aPLens.Declaration
Swift
public static func + <C, D>(lhs: PLens<S, T, A, B>, rhs: PLens<A, B, C, D>) -> PLens<S, T, C, D>Parameters
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PLensresulting from the sequential application of the two provided optics. -
Composes a
PLenswith aPIso.Declaration
Swift
public static func + <C, D>(lhs: PLens<S, T, A, B>, rhs: PIso<A, B, C, D>) -> PLens<S, T, C, D>Parameters
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PLensresulting from the sequential application of the two provided optics. -
Composes a
PLenswith aPPrism.Declaration
Swift
public static func + <C, D>(lhs: PLens<S, T, A, B>, rhs: PPrism<A, B, C, D>) -> PAffineTraversal<S, T, C, D>Parameters
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PAffineTraversalresulting from the sequential application of the two provided optics. -
Composes a
PLenswith aPAffineTraversal.Declaration
Swift
public static func + <C, D>(lhs: PLens<S, T, A, B>, rhs: PAffineTraversal<A, B, C, D>) -> PAffineTraversal<S, T, C, D>Parameters
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PAffineTraversalresulting from the sequential application of the two provided optics. -
Composes a
PLenswith aPTraversal.Declaration
Swift
public static func + <C, D>(lhs: PLens<S, T, A, B>, rhs: PTraversal<A, B, C, D>) -> PTraversal<S, T, C, D>Parameters
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PTraversalresulting from the sequential application of the two provided optics. -
Initializes a
PLenswith itsgetandsetfunctions.Declaration
Swift
public init(get: @escaping (S) -> A, set: @escaping (S, B) -> T)Parameters
getGetter function for the lens.
setSetter function for the lens.
-
Obtains the focus of this lens.
Declaration
Swift
public func get(_ s: S) -> AParameters
sSource.
Return Value
Focus for the provided source.
-
Sets the focus of this lens.
Declaration
Swift
public func set(_ s: S, _ b: B) -> TParameters
sSource.
bModified focus.
Return Value
Modified source.
-
Pairs two disjoint lenses.
Declaration
Swift
public func split<S1, T1, A1, B1>(_ other: PLens<S1, T1, A1, B1>) -> PLens<(S, S1), (T, T1), (A, A1), (B, B1)>Parameters
otherA disjoint lens.
Return Value
A lens that operates on tuples of the original and parameter sources and targets.
-
Pairs this
PLenswith another type, placing this as the first element.Declaration
Swift
public func first<C>() -> PLens<(S, C), (T, C), (A, C), (B, C)>Return Value
A
PLensthat operates on tuples where the second argument remains unchanged. -
Pairs this
PLenswith another type, placing this as the second element.Declaration
Swift
public func second<C>() -> PLens<(C, S), (C, T), (C, A), (C, B)>Return Value
A
PLensthat operates on tuples where the first argument remains unchanged. -
Composes this lens with a
PLens.Declaration
Swift
public func compose<C, D>(_ other: PLens<A, B, C, D>) -> PLens<S, T, C, D>Parameters
otherValue to compose with.
Return Value
A
PLensresulting from the sequential application of the two optics. -
Composes this lens with a
PPrism.Declaration
Swift
public func compose<C, D>(_ other: PPrism<A, B, C, D>) -> PAffineTraversal<S, T, C, D>Parameters
otherValue to compose with.
Return Value
A
PAffineTraversalresulting from the sequential application of the two optics. -
Composes this lens with a
PAffineTraversal.Declaration
Swift
public func compose<C, D>(_ other: PAffineTraversal<A, B, C, D>) -> PAffineTraversal<S, T, C, D>Parameters
otherValue to compose with.
Return Value
A
PAffineTraversalresulting from the sequential application of the two optics. -
Composes this lens with a
PLens.Declaration
Swift
public func compose<C, D>(_ other: PTraversal<A, B, C, D>) -> PTraversal<S, T, C, D>Parameters
otherValue to compose with.
Return Value
A
PTraversalresulting from the sequential application of the two optics. -
Obtains a
PAffineTraversalfrom this lens.Declaration
Swift
public var asAffineTraversal: PAffineTraversal<S, T, A, B> { get } -
Obtains a
PTraversalfrom this lens.Declaration
Swift
public var asTraversal: PTraversal<S, T, A, B> { get } -
Modifies the focus of this lens with the provided function.
Declaration
Swift
public func modify(_ s: S, _ f: @escaping (A) -> B) -> TParameters
sSource.
fModifying function.
Return Value
Modified source.
-
Lifts a function that modifies the targets, to a function that modifies the sources.
Declaration
Swift
public func lift(_ f: @escaping (A) -> B) -> (S) -> TParameters
fModifying function.
Return Value
Function that modifies sources.
-
Retrieves the target of this lens if it matches a predicate.
Declaration
Swift
public func find(_ s: S, _ predicate: (A) -> Bool) -> Option<A>Parameters
sSource.
predicateTesting predicate.
Return Value
An optional value that is present if the source matches the predicate.
-
Checks if the target of this lens matches a predicate.
Declaration
Swift
public func exists(_ s: S, _ predicate: (A) -> Bool) -> BoolParameters
sSource.
predicateTesting predicate.
Return Value
Boolean value indicating if the target of the provided source matches the predicate.
-
Combine this lens with another with the same source but different focus.
Declaration
Swift
func merge<AA, BB>(_ other: PLens<S, S, AA, BB>) -> PLens<S, S, (A, AA), (B, BB)>Parameters
otherA lens with the same source but different focus.
Return Value
A lens that lets us focus on the two foci at the same time.
Install in Dash
PLens Class Reference