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
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 }
-
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 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
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 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
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 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
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 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
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 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
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. -
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 first focus of this Traversal, if any.
Declaration
Swift
public func headOptional(_ s: S) -> 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.
-
Retrieves the last focus of this Traversal, if any.
Declaration
Swift
public func lastOptional(_ s: S) -> A?
Parameters
s
Source.
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
other
Value to compose with.
Return Value
A
PTraversal
resulting 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
other
Value to compose with.
Return Value
A
PTraversal
resulting 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
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.