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
PIso
s.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
lhs
Left side of the composition.
rhs
Right side of the composition.
Return Value
A
PIso
resulting from the sequential application of the two provided optics. -
Composes a
PIso
with 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
lhs
Left side of the composition.
rhs
Right side of the composition.
Return Value
A
PAffineTraversal
resulting from the sequential application of the two provided optics. -
Composes a
PIso
with 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
lhs
Left side of the composition.
rhs
Right side of the composition.
Return Value
A
PTraversal
resulting from the sequential application of the two provided optics. -
Creates a
PIso
with two functions that form an isomorphism.Declaration
Swift
public init(get: @escaping (S) -> A, reverseGet: @escaping (B) -> T)
Parameters
get
A function from the source to the focus.
reverseGet
A function from the modified target to the modified focus.
-
Gets the focus of an Iso.
Declaration
Swift
public func get(_ s: S) -> A
Parameters
s
Source.
Return Value
Focus of the provided source.
-
Gets the modified source of an Iso.
Declaration
Swift
public func reverseGet(_ b: B) -> T
Parameters
b
Modified 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
PIso
with reversed source and focus. -
Checks if the focus statisfies a predicate.
Declaration
Swift
public func find(_ s: S, _ predicate: (A) -> Bool) -> Option<A>
Parameters
s
Source.
predicate
Testing 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) -> T
Parameters
b
Focus.
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
other
A disjoint
PIso
to pair with this one.Return Value
A
PIso
that operates on tuples corresponding to the two joinedPIso
. -
Pairs this
PIso
with 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
PIso
that operates on tuples where the second argument remains unchanged. -
Pairs this
PIso
with 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
PIso
that 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
other
Value to compose with.
Return Value
A
PIso
resulting 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
other
Value to compose with.
Return Value
A
PAffineTraversal
resulting 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
other
Value to compose with.
Return Value
A
PTraversal
resulting 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) -> Bool
Parameters
s
Source.
predicate
Testing 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) -> T
Parameters
s
Source.
f
Function modifying the focus.
Return Value
Modified target.
-
Lifts a function to modify the focus.
Declaration
Swift
public func lift(_ f: @escaping (A) -> B) -> (S) -> T
Parameters
f
Function modifying the focus.
Return Value
Function from source to modified source.