PAffineTraversal

public class PAffineTraversal<S, T, A, B>

An AffineTraversal is an optic that allows to see into a structure and getting, setting or modifying an optional focus.

A (polymorphic) PAffineTraversal is useful when setting or modifying a value for a type with an optional polymorphic focus.

A PAffineTraversal can be seen as a weaker Lens and Prism and combines their weakest functions: - set meaning we can focus into an S and set a value B for a target A and obtain a modified source T. - getOrModify meaning it returns the focus of a PAffineTraversal (if present) or the original value.

Type parameters: - S: Source. - T: Modified source. - A: Focus. - B: Modified focus.

  • Composes a PAffineTraversal with a PAffineTraversal.

    Declaration

    Swift

    public static func + <C, D>(lhs: PAffineTraversal<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 PAffineTraversal with a PPrism.

    Declaration

    Swift

    public static func + <C, D>(lhs: PAffineTraversal<S, T, A, B>, rhs: PPrism<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 PAffineTraversal with a PLens.

    Declaration

    Swift

    public static func + <C, D>(lhs: PAffineTraversal<S, T, A, B>, rhs: PLens<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 PAffineTraversal with a PIso.

    Declaration

    Swift

    public static func + <C, D>(lhs: PAffineTraversal<S, T, A, B>, rhs: PIso<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 PAffineTraversal with a PSetter.

    Declaration

    Swift

    public static func + <C, D>(lhs: PAffineTraversal<S, T, A, B>, rhs: PSetter<A, B, C, D>) -> PSetter<S, T, C, D>

    Parameters

    lhs

    Left side of the composition.

    rhs

    Right side of the composition.

    Return Value

    A PSetter resulting from the sequential application of the two provided optics.

  • Composes a PAffineTraversal with a Getter.

    Declaration

    Swift

    public static func + <C>(lhs: PAffineTraversal<S, T, A, B>, rhs: Getter<A, C>) -> Fold<S, C>

    Parameters

    lhs

    Left side of the composition.

    rhs

    Right side of the composition.

    Return Value

    A Fold resulting from the sequential application of the two provided optics.

  • Composes a PAffineTraversal with a Fold.

    Declaration

    Swift

    public static func + <C>(lhs: PAffineTraversal<S, T, A, B>, rhs: Fold<A, C>) -> Fold<S, C>

    Parameters

    lhs

    Left side of the composition.

    rhs

    Right side of the composition.

    Return Value

    A Fold resulting from the sequential application of the two provided optics.

  • Composes a PAffineTraversal with a PTraversal.

    Declaration

    Swift

    public static func + <C, D>(lhs: PAffineTraversal<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.

  • Provides an AffineTraversal that never sees its focus.

    Declaration

    Swift

    public static var void: AffineTraversal<S, A> { get }
  • Initializes a PAffineTraversal.

    Declaration

    Swift

    public init(set: @escaping (S, B) -> T, getOrModify: @escaping (S) -> Either<T, A>)

    Parameters

    set

    Setter function.

    getOrModify

    Getter function.

  • Gets a modified source.

    Declaration

    Swift

    public func set(_ s: S, _ b: B) -> T

    Parameters

    s

    Source.

    b

    Modified focus.

    Return Value

    Modified source.

  • Gets the focus or the modified source.

    Declaration

    Swift

    public func getOrModify(_ s: S) -> Either<T, A>

    Parameters

    s

    Source.

    Return Value

    Either the focus or the modified source.

  • Modifies the focus of a PAffineTraversal with an Applicative function.

    Declaration

    Swift

    public func modifyF<F: Applicative>(_ s: S, _ f: @escaping (A) -> Kind<F, B>) -> Kind<F, T>

    Parameters

    s

    Source.

    f

    Modifying function.

    Return Value

    Modified source in the context of the Applicative.

  • Lifts an Applicative function operating on the focus to one operating on the source.

    Declaration

    Swift

    public func liftF<F: Applicative>(_ f: @escaping (A) -> Kind<F, B>) -> (S) -> Kind<F, T>

    Parameters

    f

    Modifying function.

    Return Value

    Lifted function in the context of the source.

  • Gets the focus or Option.none if it is not present.

    Declaration

    Swift

    public func getOption(_ s: S) -> Option<A>

    Parameters

    s

    Source.

    Return Value

    Focus or Option.none if it is not present.

  • Gets the focus or nil if it is not present.

    Declaration

    Swift

    public func getOptional(_ s: S) -> A?

    Parameters

    s

    Source.

    Return Value

    Focus or nil if it is not present.

  • Sets a new value for the focus.

    Declaration

    Swift

    public func setOption(_ s: S, _ b: B) -> Option<T>

    Parameters

    s

    Source.

    b

    New focus.

    Return Value

    Optional modified source.

  • Sets a new value for the focus.

    Declaration

    Swift

    public func setOptional(_ s: S, _ b: B) -> T?

    Parameters

    s

    Source.

    b

    New focus.

    Return Value

    Optional modified source.

  • Checks if the provided source is empty (i.e. does not have a focus).

    Declaration

    Swift

    public func isEmpty(_ s: S) -> Bool

    Parameters

    s

    Source.

    Return Value

    Boolean value indicating if the source is empty.

  • Checks if the provided source is non-empty (i.e. does have a focus).

    Declaration

    Swift

    public func nonEmpty(_ s: S) -> Bool

    Parameters

    s

    Source.

    Return Value

    Boolean value indicating if the source is non-empty.

  • Joins with a PAffineTraversal with the same focus.

    Declaration

    Swift

    public func choice<S1, T1>(_ other: PAffineTraversal<S1, T1, A, B>) -> PAffineTraversal<Either<S, S1>, Either<T, T1>, A, B>

    Parameters

    other

    Value to join with.

    Return Value

    A PAffineTraversal that operates in either of the original sources.

  • Pairs this PAffineTraversal with another type, placing this as the first element.

    Declaration

    Swift

    public func first<C>() -> PAffineTraversal<(S, C), (T, C), (A, C), (B, C)>

    Return Value

    A PAffineTraversal that operates on tuples where the second argument remains unchanged.

  • Pairs this PAffineTraversal with another type, placing this as the second element.

    Declaration

    Swift

    public func second<C>() -> PAffineTraversal<(C, S), (C, T), (C, A), (C, B)>

    Return Value

    A PAffineTraversal that operates on tuples where the first argument remains unchanged.

  • Modifies the focus with a function.

    Declaration

    Swift

    public func modify(_ s: S, _ f: @escaping (A) -> B) -> T

    Parameters

    s

    Source.

    f

    Modifying function.

    Return Value

    Modified source.

  • Lifts a function modifying the focus to a function modifying the source.

    Declaration

    Swift

    public func lift(_ f: @escaping (A) -> B) -> (S) -> T

    Parameters

    f

    Modifying function.

    Return Value

    A function modifying the source.

  • Modifies the source with a function if it matches.

    Declaration

    Swift

    public func modifyOption(_ s: S, _ f : @escaping (A) -> B) -> Option<T>

    Parameters

    s

    Source.

    f

    Modifying function.

    Return Value

    An optional modified source that is present if the modification took place.

  • Retrieves the focus if it matches a predicate.

    Declaration

    Swift

    public func find(_ s: S, _ predicate: @escaping (A) -> Bool) -> Option<A>

    Parameters

    s

    Source.

    predicate

    Testing 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) -> Bool

    Parameters

    s

    Source.

    predicate

    Testing predicate.

    Return Value

    A 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) -> Bool

    Parameters

    s

    Source.

    predicate

    Testing predicate.

    Return Value

    A Boolean value indicating if the focus matches the predicate.

  • Composes this value 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 the sequential application of the two provided optics.

  • Composes this value with a PPrism.

    Declaration

    Swift

    public func compose<C, D>(_ other: PPrism<A, B, C, D>) -> PAffineTraversal<S, T, C, D>

    Parameters

    other

    Value to compose with.

    Return Value

    A PAffineTraversal resulting 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

    other

    Value to compose with.

    Return Value

    A PAffineTraversal resulting from the sequential application of the two provided optics.

  • Composes this value with a PIso.

    Declaration

    Swift

    public func compose<C, D>(_ other: PIso<A, B, C, D>) -> PAffineTraversal<S, T, C, D>

    Parameters

    other

    Value to compose with.

    Return Value

    A PAffineTraversal resulting from the sequential application of the two provided optics.

  • Composes this value with a PSetter.

    Declaration

    Swift

    public func compose<C, D>(_ other: PSetter<A, B, C, D>) -> PSetter<S, T, C, D>

    Parameters

    other

    Value to compose with.

    Return Value

    A PSetter resulting from the sequential application of the two provided optics.

  • Composes this value with a Getter.

    Declaration

    Swift

    public func compose<C>(_ other: Getter<A, C>) -> Fold<S, C>

    Parameters

    other

    Value to compose with.

    Return Value

    A Fold resulting from the sequential application of the two provided optics.

  • Composes this value with a PPrism.

    Declaration

    Swift

    public func compose<C>(_ other: Fold<A, C>) -> Fold<S, C>

    Parameters

    other

    Value to compose with.

    Return Value

    A PAffineTraversal resulting 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

    other

    Value to compose with.

    Return Value

    A PAffineTraversal resulting from the sequential application of the two provided optics.

  • Converts this value as a PSetter.

    Declaration

    Swift

    public var asSetter: PSetter<S, T, A, B> { get }
  • Converts this value as a Fold.

    Declaration

    Swift

    public var asFold: Fold<S, A> { get }
  • Converts this value as a PTraversal.

    Declaration

    Swift

    public var asTraversal: PTraversal<S, T, A, B> { get }
  • Extracts the focus viewed through the PAffineTraversal.

    Declaration

    Swift

    public func extract() -> State<S, Option<A>>

    Return Value

    A State of the source and target.

  • Extracts the focus viewed through the PAffineTraversal.

    Declaration

    Swift

    public func toState() -> State<S, Option<A>>

    Return Value

    A State of the source and target.

  • Extracts the focus viewed through the PAffineTraversal and applies the provided function to it.

    Declaration

    Swift

    public func extractMap<C>(_ f: @escaping (A) -> C) -> State<S, Option<C>>

    Return Value

    A State of the source and target, modified by the provided function.