PIso
public class PIso<S, T, A, B>
An Iso is a loss less invertible optic that defines an isomorphism between a type S and A.
A polimorphic PIso is useful when setting or modifying a value for a constructed type; e.g. PIso<<Option<Int>, Option<String>, Int?, String?>.
S: Source of aPIso.T: Modified source of aPIso.A: Focus of aPIso.B: Modified target of aPIso.
-
Composes two
PIsos.Declaration
Swift
public static func + <C, D>(lhs: PIso<S, T, A, B>, rhs: PIso<A, B, C, D>) -> PIso<S, T, C, D>Parameters
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PIsoresulting from the sequential application of the two provided optics. -
Composes a
PIsowith aPAffineTraversal.Declaration
Swift
public static func + <C, D>(lhs: PIso<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
PIsowith aPTraversal.Declaration
Swift
public static func + <C, D>(lhs: PIso<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. -
Creates a
PIsowith two functions that form an isomorphism.Declaration
Swift
public init(get: @escaping (S) -> A, reverseGet: @escaping (B) -> T)Parameters
getA function from the source to the focus.
reverseGetA function from the modified target to the modified focus.
-
Gets the focus of an Iso.
Declaration
Swift
public func get(_ s: S) -> AParameters
sSource.
Return Value
Focus of the provided source.
-
Gets the modified source of an Iso.
Declaration
Swift
public func reverseGet(_ b: B) -> TParameters
bModified target.
Return Value
Modified source of the provided modified target.
-
Reverses the source and focus of this
PIso.Declaration
Swift
public func reverse() -> PIso<B, A, T, S>Return Value
A
PIsowith reversed source and focus. -
Checks if the focus statisfies a predicate.
Declaration
Swift
public func find(_ s: S, _ predicate: (A) -> Bool) -> Option<A>Parameters
sSource.
predicateTesting predicate.
Return Value
A present option with the focus, if it satisfies the predicate; or none, otherwise.
-
Sets the focus of a
PIso.Declaration
Swift
public func set(_ b: B) -> TParameters
bFocus.
Return Value
Source for the provided focus.
-
Pairs two disjoint
PIso.Declaration
Swift
public func split<S1, T1, A1, B1>(_ other: PIso<S1, T1, A1, B1>) -> PIso<(S, S1), (T, T1), (A, A1), (B, B1)>Parameters
otherA disjoint
PIsoto pair with this one.Return Value
A
PIsothat operates on tuples corresponding to the two joinedPIso. -
Pairs this
PIsowith another type, placing this as the first element.Declaration
Swift
public func first<C>() -> PIso<(S, C), (T, C), (A, C), (B, C)>Return Value
A
PIsothat operates on tuples where the second argument remains unchanged. -
Pairs this
PIsowith another type, placing this as the second element.Declaration
Swift
public func second<C>() -> PIso<(C, S), (C, T), (C, A), (C, B)>Return Value
A
PIsothat operates on tuples where the first argument remains unchaged. -
Composes this with a
PIso.Declaration
Swift
public func compose<C, D>(_ other: PIso<A, B, C, D>) -> PIso<S, T, C, D>Parameters
otherValue to compose with.
Return Value
A
PIsoresulting from applying the two optics sequentially. -
Composes this 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 applying the two optics sequentially. -
Composes this with a
PTraversal.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 applying the two optics sequentially. -
Converts this into a
PAffineTraversal.Declaration
Swift
public var asAffineTraversal: PAffineTraversal<S, T, A, B> { get } -
Converts this into a
PTraversal.Declaration
Swift
public var asTraversal: PTraversal<S, T, A, B> { get } -
Checks if the target fulfils a predicate.
Declaration
Swift
public func exists(_ s: S, _ predicate: (A) -> Bool) -> BoolParameters
sSource.
predicateTesting predicate.
Return Value
A boolean value indicating if the target matches the provided predicate.
-
Modifies the focus with a function.
Declaration
Swift
public func modify(_ s: S, _ f: @escaping (A) -> B) -> TParameters
sSource.
fFunction modifying the focus.
Return Value
Modified target.
-
Lifts a function to modify the focus.
Declaration
Swift
public func lift(_ f: @escaping (A) -> B) -> (S) -> TParameters
fFunction modifying the focus.
Return Value
Function from source to modified source.
Install in Dash
PIso Class Reference