PTraversal
open class PTraversal<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 with an
Applicativefunction.Declaration
Swift
open 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. -
Provides a Traversal with no focus.
Declaration
Swift
public static var void: Traversal<S, A> { get } -
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
get11st getter.
get22nd getter.
setSetter.
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
get11st getter.
get22nd getter.
get33rd getter.
setSetter.
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
get11st getter.
get22nd getter.
get33rd getter.
get44th getter.
setSetter.
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
get11st getter.
get22nd getter.
get33rd getter.
get44th getter.
get55th getter.
setSetter.
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
get11st getter.
get22nd getter.
get33rd getter.
get44th getter.
get55th getter.
get66th getter.
setSetter.
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
get11st getter.
get22nd getter.
get33rd getter.
get44th getter.
get55th getter.
get66th getter.
get77th getter.
setSetter.
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
get11st getter.
get22nd getter.
get33rd getter.
get44th getter.
get55th getter.
get66th getter.
get77th getter.
get88th getter.
setSetter.
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
get11st getter.
get22nd getter.
get33rd getter.
get44th getter.
get55th getter.
get66th getter.
get77th getter.
get88th getter.
get99th getter.
setSetter.
Return Value
A Traversal from the provided getters and setter.
-
Composes a
PTraversalwith aPTraversal.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
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PTraversalresulting from the sequential application of the two provided optics. -
Composes a
PTraversalwith aPAffineTraversal.Declaration
Swift
public static func + <C, D>(lhs: PTraversal<S, T, A, B>, rhs: PAffineTraversal<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. -
Composes a
PTraversalwith aPPrism.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
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PTraversalresulting from the sequential application of the two provided optics. -
Composes a
PTraversalwith aPLens.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
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PTraversalresulting from the sequential application of the two provided optics. -
Composes a
PTraversalwith aPIso.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
lhsLeft side of the composition.
rhsRight side of the composition.
Return Value
A
PTraversalresulting from the sequential application of the two provided optics. -
Sets a new focus.
Declaration
Swift
public func set(_ s: S, _ b: B) -> TParameters
sSource.
bModified focus.
Return Value
Modified source.
-
Counts the number of foci.
Declaration
Swift
public func size(_ s: S) -> IntParameters
sSource.
Return Value
Number of foci in this Traversal.
-
Checks if this Traversal has any focus.
Declaration
Swift
public func isEmpty(_ s: S) -> BoolParameters
sSource.
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) -> BoolParameters
sSource.
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
sSource.
Return Value
An optional value with the first focus of the source, if any.
-
Retrieves the first focus of this Traversal, if any.
Declaration
Swift
public func headOptional(_ s: S) -> A?Parameters
sSource.
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
sSource.
Return Value
An optional value with the last focus of the source, if any.
-
Retrieves the last focus of this Traversal, if any.
Declaration
Swift
public func lastOptional(_ s: S) -> A?Parameters
sSource.
Return Value
An optional value with the last focus of the source, if any.
-
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 the sequential application of the two optics. -
Composes this with a
PAffineTraversal.Declaration
Swift
public func compose<C, D>(_ other: PAffineTraversal<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 optics. -
Obtains the first focus that matches a predicate.
Declaration
Swift
public func find(_ s: S, _ predicate: @escaping (A) -> Bool) -> Option<A>Parameters
sSource.
predicateTesting 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) -> TParameters
sSource.
fModifying function.
Return Value
Modified source.
-
Checks if any focus matches a predicate.
Declaration
Swift
public func exists(_ s: S, _ predicate: @escaping (A) -> Bool) -> BoolParameters
sSource.
predicateTesting 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) -> BoolParameters
sSource.
predicateTesting predicate.
Return Value
True if all foci match the predicate; false otherwitse.
Install in Dash
PTraversal Class Reference