PTraversal

open class PTraversal<S, T, A, B> : PTraversalOf<S, T, A, B>

A Traversal is an optic that allows to see into a structure with 0 to N foci.

Traversal is a generalization of Traverse and can be seen as a representation of modifyF. All methods are written in terms of modifyF.

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

  • Modifies the source wiht an Applicative function.

    Declaration

    Swift

    open 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.

  • Provides a Traversal with no focus.

    Declaration

    Swift

    public static var void: Traversal<S, A> { get }
  • Provides a Traversal based on the implementation of Traverse for F.

    Declaration

    Swift

    public static func fromTraverse<F>() -> PTraversal<Kind<F, A>, Kind<F, B>, A, B> where S : Kind<F, A>, T : Kind<F, B>, F : Traverse

    Return Value

    A Traversal based on the implementation of Traverse for F.

  • Creates a Traversal from multiple getters of the same source.

    Declaration

    Swift

    public static func from(_ get1: @escaping (S) -> A,
                            _ get2: @escaping (S) -> A,
                            _ set: @escaping (B, B, S) -> T) -> PTraversal<S, T, A, B>

    Parameters

    get1

    1st getter.

    get2

    2nd getter.

    set

    Setter.

    Return Value

    A Traversal from the provided getters and setter.

  • Creates a Traversal from multiple getters of the same source.

    Declaration

    Swift

    public static func from(_ get1: @escaping (S) -> A,
                            _ get2: @escaping (S) -> A,
                            _ get3: @escaping (S) -> A,
                            _ set: @escaping (B, B, B, S) -> T) -> PTraversal<S, T, A, B>

    Parameters

    get1

    1st getter.

    get2

    2nd getter.

    get3

    3rd getter.

    set

    Setter.

    Return Value

    A Traversal from the provided getters and setter.

  • Creates a Traversal from multiple getters of the same source.

    Declaration

    Swift

    public static func from(_ get1: @escaping (S) -> A,
                            _ get2: @escaping (S) -> A,
                            _ get3: @escaping (S) -> A,
                            _ get4: @escaping (S) -> A,
                            _ set: @escaping (B, B, B, B, S) -> T) -> PTraversal<S, T, A, B>

    Parameters

    get1

    1st getter.

    get2

    2nd getter.

    get3

    3rd getter.

    get4

    4th getter.

    set

    Setter.

    Return Value

    A Traversal from the provided getters and setter.

  • Creates a Traversal from multiple getters of the same source.

    Declaration

    Swift

    public static func from(_ get1: @escaping (S) -> A,
                            _ get2: @escaping (S) -> A,
                            _ get3: @escaping (S) -> A,
                            _ get4: @escaping (S) -> A,
                            _ get5: @escaping (S) -> A,
                            _ set: @escaping (B, B, B, B, B, S) -> T) -> PTraversal<S, T, A, B>

    Parameters

    get1

    1st getter.

    get2

    2nd getter.

    get3

    3rd getter.

    get4

    4th getter.

    get5

    5th getter.

    set

    Setter.

    Return Value

    A Traversal from the provided getters and setter.

  • Creates a Traversal from multiple getters of the same source.

    Declaration

    Swift

    public static func from(_ get1: @escaping (S) -> A,
                            _ get2: @escaping (S) -> A,
                            _ get3: @escaping (S) -> A,
                            _ get4: @escaping (S) -> A,
                            _ get5: @escaping (S) -> A,
                            _ get6: @escaping (S) -> A,
                            _ set : @escaping (B, B, B, B, B, B, S) -> T) -> PTraversal<S, T, A, B>

    Parameters

    get1

    1st getter.

    get2

    2nd getter.

    get3

    3rd getter.

    get4

    4th getter.

    get5

    5th getter.

    get6

    6th getter.

    set

    Setter.

    Return Value

    A Traversal from the provided getters and setter.

  • Creates a Traversal from multiple getters of the same source.

    Declaration

    Swift

    public static func from(_ get1: @escaping (S) -> A,
                            _ get2: @escaping (S) -> A,
                            _ get3: @escaping (S) -> A,
                            _ get4: @escaping (S) -> A,
                            _ get5: @escaping (S) -> A,
                            _ get6: @escaping (S) -> A,
                            _ get7: @escaping (S) -> A,
                            _ set: @escaping (B, B, B, B, B, B, B, S) -> T) -> PTraversal<S, T, A, B>

    Parameters

    get1

    1st getter.

    get2

    2nd getter.

    get3

    3rd getter.

    get4

    4th getter.

    get5

    5th getter.

    get6

    6th getter.

    get7

    7th getter.

    set

    Setter.

    Return Value

    A Traversal from the provided getters and setter.

  • Creates a Traversal from multiple getters of the same source.

    Declaration

    Swift

    public static func from(_ get1: @escaping (S) -> A,
                            _ get2: @escaping (S) -> A,
                            _ get3: @escaping (S) -> A,
                            _ get4: @escaping (S) -> A,
                            _ get5: @escaping (S) -> A,
                            _ get6: @escaping (S) -> A,
                            _ get7: @escaping (S) -> A,
                            _ get8: @escaping (S) -> A,
                            _ set: @escaping (B, B, B, B, B, B, B, B, S) -> T) -> PTraversal<S, T, A, B>

    Parameters

    get1

    1st getter.

    get2

    2nd getter.

    get3

    3rd getter.

    get4

    4th getter.

    get5

    5th getter.

    get6

    6th getter.

    get7

    7th getter.

    get8

    8th getter.

    set

    Setter.

    Return Value

    A Traversal from the provided getters and setter.

  • Creates a Traversal from multiple getters of the same source.

    Declaration

    Swift

    public static func from(_ get1: @escaping (S) -> A,
                            _ get2: @escaping (S) -> A,
                            _ get3: @escaping (S) -> A,
                            _ get4: @escaping (S) -> A,
                            _ get5: @escaping (S) -> A,
                            _ get6: @escaping (S) -> A,
                            _ get7: @escaping (S) -> A,
                            _ get8: @escaping (S) -> A,
                            _ get9: @escaping (S) -> A,
                            _ set: @escaping (B, B, B, B, B, B, B, B, B, S) -> T) -> PTraversal<S, T, A, B>

    Parameters

    get1

    1st getter.

    get2

    2nd getter.

    get3

    3rd getter.

    get4

    4th getter.

    get5

    5th getter.

    get6

    6th getter.

    get7

    7th getter.

    get8

    8th getter.

    get9

    9th getter.

    set

    Setter.

    Return Value

    A Traversal from the provided getters and setter.

  • Composes a PTraversal with a PTraversal.

    Declaration

    Swift

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

  • Composes a PTraversal with a PSetter.

    Declaration

    Swift

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

    Declaration

    Swift

    public static func + <C>(lhs: PTraversal<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 PTraversal with a POptional.

    Declaration

    Swift

    public static func + <C, D>(lhs: PTraversal<S, T, A, B>, rhs: POptional<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.

  • Composes a PTraversal with a PPrism.

    Declaration

    Swift

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

  • Composes a PTraversal with a PLens.

    Declaration

    Swift

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

  • Composes a PTraversal with a PIso.

    Declaration

    Swift

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

  • Transforms all foci in this Traversal and folds them using their Monoid instance.

    Declaration

    Swift

    public func foldMap<R: Monoid>(_ s: S, _ f: @escaping (A) -> R) -> R

    Parameters

    s

    Source.

    f

    Transforming function.

    Return Value

    A summary value of the transformation and folding.

  • Obtains all foci.

    Declaration

    Swift

    public func getAll(_ s: S) -> ArrayK<A>

    Parameters

    s

    Source

    Return Value

    An ArrayK with all foci.

  • Sets a new focus.

    Declaration

    Swift

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

    Parameters

    s

    Source.

    b

    Modified focus.

    Return Value

    Modified source.

  • Counts the number of foci.

    Declaration

    Swift

    public func size(_ s: S) -> Int

    Parameters

    s

    Source.

    Return Value

    Number of foci in this Traversal.

  • Checks if this Traversal has any focus.

    Declaration

    Swift

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

    Parameters

    s

    Source.

    Return Value

    True if this Traversal do not have any focus; false otherwise.

  • Checks if this Traversal has any focus.

    Declaration

    Swift

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

    Parameters

    s

    Source.

    Return Value

    False if this Traversal do not have any focus; true otherwise.

  • Retrieves the first focus of this Traversal, if any.

    Declaration

    Swift

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

    Parameters

    s

    Source.

    Return Value

    An optional value with the first focus of the source, if any.

  • Retrieves the last focus of this Traversal, if any.

    Declaration

    Swift

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

    Parameters

    s

    Source.

    Return Value

    An optional value with the last focus of the source, if any.

  • Joins two Traversal with the same focus.

    Declaration

    Swift

    public func choice<U, V>(_ other: PTraversal<U, V, A, B>) -> PTraversal<Either<S, U>, Either<T, V>, A, B>

    Parameters

    other

    Value to join with.

    Return Value

    A Traversal that operates on either of the original sources.

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

  • Composes this 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 optics.

  • Composes this with a Fold.

    Declaration

    Swift

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

    Parameters

    other

    Value to compose with.

    Return Value

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

  • Composes this with a POptional.

    Declaration

    Swift

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

    Parameters

    other

    Value to compose with.

    Return Value

    A PTraversal resulting from the sequential application of the two optics.

  • Composes this with a PPrism.

    Declaration

    Swift

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

    Parameters

    other

    Value to compose with.

    Return Value

    A PTraversal resulting from the sequential application of the two optics.

  • Composes this with a PLens.

    Declaration

    Swift

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

    Parameters

    other

    Value to compose with.

    Return Value

    A PTraversal resulting from the sequential application of the two optics.

  • Composes this with a PIso.

    Declaration

    Swift

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

    Parameters

    other

    Value to compose with.

    Return Value

    A PTraversal resulting from the sequential application of the two optics.

  • Converts this to a PSetter.

    Declaration

    Swift

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

    Declaration

    Swift

    public var asFold: Fold<S, A> { get }
  • Obtains the first focus that 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 value with the first focus that matches the predicate, if any.

  • 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.

  • Checks if any focus matches a predicate.

    Declaration

    Swift

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

    Parameters

    s

    Source.

    predicate

    Testing predicate.

    Return Value

    True if any focus matches the predicate; false otherwise.

  • Checks if all foci match a predicate.

    Declaration

    Swift

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

    Parameters

    s

    Source.

    predicate

    Testing predicate.

    Return Value

    True if all foci match the predicate; false otherwitse.

  • Extracts the focus viewed through the PTraversal.

    Declaration

    Swift

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

    Return Value

    A State of the source and target.

  • Extracts the focus viewed through the PTraversal.

    Declaration

    Swift

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

    Return Value

    A State of the source and target.

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

    Declaration

    Swift

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

    Return Value

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

  • Folds all foci using their instance of Monoid.

    Declaration

    Swift

    public func fold(_ s: S) -> A

    Parameters

    s

    Source.

    Return Value

    Comination of all foci using their instance of Monoid.

  • Folds all foci using their instance of Monoid.

    Declaration

    Swift

    public func combineAll(_ s: S) -> A

    Parameters

    s

    Source.

    Return Value

    Comination of all foci using their instance of Monoid.