PPrism
public class PPrism<S, T, A, B>
A Prism is a loss less invertible optic that can look into a structure and optionally find its focus. It is mostly used for finding a focus that is only present under certain conditions, like in a sum type.
A (polymorphic) PPrism is useful when setting or modifying a value for a polymorphic sum type.
A PPrism gathres the two concepts of pattern matching and constructor and thus can be seen as a pair of functions:
- getOrModify meaning it returns the focus of a PPRism or the original value.
- reverseGet meaining we can construct the source type of a PPrism from a focus.
Type parameters:
- S: Source.
- T: Modified source.
- A: Focus.
- B: Modified focus.
-
Composes a
PPrismwith aPPrism.Declaration
Swift
public static func + <C, D>(lhs: PPrism<S, T, A, B>, rhs: PPrism<A, B, C, D>) -> PPrism<S, T, C, D>Parameters
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PPrismresulting from the sequential application of the two provided optics. -
Composes a
PPrismwith aPIso.Declaration
Swift
public static func + <C, D>(lhs: PPrism<S, T, A, B>, rhs: PIso<A, B, C, D>) -> PPrism<S, T, C, D>Parameters
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PPrismresulting from the sequential application of the two provided optics. -
Composes a
PPrismwith aPLens.Declaration
Swift
public static func + <C, D>(lhs: PPrism<S, T, A, B>, rhs: PLens<A, B, C, D>) -> PAffineTraversal<S, T, C, D>Parameters
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
AffineTraversalresulting from the sequential application of the two provided optics. -
Composes a
PPrismwith aAffineTraversal.Declaration
Swift
public static func + <C, D>(lhs: PPrism<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
AffineTraversalresulting from the sequential application of the two provided optics. -
Composes a
PPrismwith aPTraversal.Declaration
Swift
public static func + <C, D>(lhs: PPrism<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 Prism.
Declaration
Swift
public init(getOrModify: @escaping (S) -> Either<T, A>, reverseGet: @escaping (B) -> T)Parameters
getOrModifyGets the focus of the prism, if present.
reverseGetBuilds the source of the prism from its focus.
-
Retrieves the focus or modifies the source.
Declaration
Swift
public func getOrModify(_ s: S) -> Either<T, A>Parameters
sSource.
Return Value
Either the modified source or the focus of the prism.
-
Obtains a modified source.
Declaration
Swift
public func reverseGet(_ b: B) -> TParameters
bModified focus.
Return Value
Modified source.
-
Modifies the focus of a PPrism with an
Applicativefunction.Declaration
Swift
public func modifyF<F: Applicative>(_ s: S, _ f: @escaping (A) -> Kind<F, B>) -> Kind<F, T>Parameters
sSource.
fModifying function.
Return Value
Modified source in the context of the
Applicative. -
Lifts an
Applicativefunction operating on focus to one operating on source.Declaration
Swift
public func liftF<F: Applicative>(_ f: @escaping (A) -> Kind<F, B>) -> (S) -> Kind<F, T>Parameters
fModifying function.
Return Value
Lifted function operating on the source.
-
Retrieves the focus.
Declaration
Swift
public func getOption(_ s: S) -> Option<A>Parameters
sSource.
Return Value
An optional value that is present if the focus exists.
-
Retrieves the focus.
Declaration
Swift
public func getOptional(_ s: S) -> A?Parameters
sSource.
Return Value
An optional value that is present if the focus exists.
-
Obtains a modified source.
Declaration
Swift
public func set(_ s: S, _ b: B) -> TParameters
sSource.
bModified focus.
Return Value
Modified source.
-
Sets a modified focus.
Declaration
Swift
public func setOption(_ s: S, _ b: B) -> Option<T>Parameters
sSource.
bModified focus.
Return Value
Optional modified source.
-
Sets a modified focus.
Declaration
Swift
public func setOptional(_ s: S, _ b: B) -> T?Parameters
sSource.
bModified focus.
Return Value
Optional modified source.
-
Checks if the provided source is non-empty.
Declaration
Swift
public func nonEmpty(_ s: S) -> BoolParameters
sSource.
Return Value
Boolean value indicating if the provided source is non-empty.
-
Checks if the provided source is empty.
Declaration
Swift
public func isEmpty(_ s: S) -> BoolParameters
sSource.
Return Value
Boolean value indicating if the provided source is empty.
-
Pairs this
PPrismwith another type, placing this as the first element.Declaration
Swift
public func first<C>() -> PPrism<(S, C), (T, C), (A, C), (B, C)>Return Value
A
PPrismthat operates on tuples where the second argument remains unchanged. -
Pairs this
PPrismwith another type, placing this as the second element.Declaration
Swift
public func second<C>() -> PPrism<(C, S), (C, T), (C, A), (C, B)>Return Value
A
PPrismthat operates on tuples where the first argument remains unchanged. -
Modifies the source 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 modifying the focus to one modifying the source.
Declaration
Swift
public func lift(_ f: @escaping (A) -> B) -> (S) -> TParameters
fModifying function.
Return Value
Function that modifies the source.
-
Optionally modifies the source with a function.
Declaration
Swift
public func modifyOption(_ s: S, _ f: @escaping (A) -> B) -> Option<T>Parameters
sSource.
fModifying function.
Return Value
Optional modified source.
-
Lifts a function modifying the focus to a function that optionally modifies the source.
Declaration
Swift
public func liftOption(_ f: @escaping (A) -> B) -> (S) -> Option<T>Parameters
fModifying function.
Return Value
Function that optionally modifies the source.
-
Retrieves the focus if it matches a predicate.
Declaration
Swift
public func find(_ s: S, _ predicate: @escaping (A) -> Bool) -> Option<A>Parameters
sSource.
predicateTesting predicate.
Return Value
An optional focus that is present if it matches the predicate.
-
Checks if the focus matches a predicate.
Declaration
Swift
public func exists(_ s: S, _ predicate: @escaping (A) -> Bool) -> BoolParameters
sSource.
predicateTesting predicate.
Return Value
Boolean value indicating if the focus matches the predicate.
-
Checks if the focus matches a predicate.
Declaration
Swift
public func all(_ s: S, _ predicate: @escaping(A) -> Bool) -> BoolParameters
sSource.
predicateTesting predicate.
Return Value
Boolean value indicating if the focus matches the predicate.
-
Composes this value with a
PPrism.Declaration
Swift
public func compose<C, D>(_ other: PPrism<A, B, C, D>) -> PPrism<S, T, C, D>Parameters
otherValue to compose with.
Return Value
A
PPrismresulting from the sequential application of the two provided optics. -
Composes this value with a
PLens.Declaration
Swift
public func compose<C, D>(_ other: PLens<A, B, C, D>) -> PAffineTraversal<S, T, C, D>Parameters
otherValue to compose with.
Return Value
A
AffineTraversalresulting from the sequential application of the two provided optics. -
Composes this value with a
AffineTraversal.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
AffineTraversalresulting from the sequential application of the two provided optics. -
Composes this value 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 the sequential application of the two provided optics. -
Converts this value into a AffineTraversal.
Declaration
Swift
public var asAffineTraversal: PAffineTraversal<S, T, A, B> { get } -
Converts this value into a PSetter.
Declaration
Swift
public var asSetter: PSetter<S, T, A, B> { get } -
Converts this value into a Fold.
Declaration
Swift
public var asFold: Fold<S, A> { get } -
Converts this value into a PTraversal.
Declaration
Swift
public var asTraversal: PTraversal<S, T, A, B> { get }
Install in Dash
PPrism Class Reference