Getter
public class Getter<S, A>
A Getter
is an optic that allows to see into a structure and getting a focus.
It can be seen as a function (S) -> A
meaning that we can look into an S
and get an A
.
Parameters:
- S
: source of the Getter
.
- A
: focus of the Getter
.
-
Composes a
Getter
with anotherGetter
.Declaration
Swift
public static func + <C>(lhs: Getter<S, A>, rhs: Getter<A, C>) -> Getter<S, C>
Parameters
lhs
Left side of the composition.
rhs
Right side of the composition.
Return Value
A
Getter
resulting from the sequential application of the two provided optics. -
Composes a
Getter
with aLens
.Declaration
Swift
public static func + <C>(lhs: Getter<S, A>, rhs: Lens<A, C>) -> Getter<S, C>
Parameters
lhs
Left side of the composition.
rhs
Right side of the composition.
Return Value
A
Getter
resulting from the sequential application of the two provided optics. -
Composes a
Getter
with anIso
.Declaration
Swift
public static func + <C>(lhs: Getter<S, A>, rhs: Iso<A, C>) -> Getter<S, C>
Parameters
lhs
Left side of the composition.
rhs
Right side of the composition.
Return Value
A
Getter
resulting from the sequential application of the two provided optics. -
Initializes a Getter.
Declaration
Swift
public init(get: @escaping (S) -> A)
Parameters
get
Function to focus into a structure.
-
Obtains the focus for a given source.
Declaration
Swift
public func get(_ s: S) -> A
Parameters
s
Source.
Return Value
Focus.
-
Joins two Getters with the same focus.
Declaration
Swift
public func choice<C>(_ other: Getter<C, A>) -> Getter<Either<S, C>, A>
Parameters
other
Getter
to join with.Return Value
A
Getter
that operates on either of the sources and extracts their focus. -
Pairs two disjoint Getters.
Declaration
Swift
public func split<C, D>(_ other: Getter<C, D>) -> Getter<(S, C), (A, D)>
Parameters
other
Getter
to pair with.Return Value
A
Getter
that operates in both sources at the same time, extracting both foci. -
Zips two Getters with the same source.
Declaration
Swift
public func zip<C>(_ other: Getter<S, C>) -> Getter<S, (A, C)>
Parameters
other
Getter
to zip with.Return Value
A
Getter
that extracts both foci for a given source. -
Pairs this
Getter
with another type, placing this as the first element.Declaration
Swift
public func first<C>() -> Getter<(S, C), (A, C)>
Return Value
A
Getter
that operates on tuples where the second argument remains unchanged. -
Pairs this
Getter
with another type, placing this as the second element.Declaration
Swift
public func second<C>() -> Getter<(C, S), (C, A)>
Return Value
A
Getter
that operates on tuples where the first argument remains unchanged. -
Composes this
Getter
with aGetter
.Declaration
Swift
public func compose<C>(_ other: Getter<A, C>) -> Getter<S, C>
Parameters
other
Value to compose with.
Return Value
A
Getter
resulting from the sequential application of both optics. -
Composes this
Getter
with aLens
.Declaration
Swift
public func compose<C>(_ other: Lens<A, C>) -> Getter<S, C>
Parameters
other
Value to compose with.
Return Value
A
Getter
resulting from the sequential application of both optics. -
Composes this
Getter
with anIso
.Declaration
Swift
public func compose<C>(_ other: Iso<A, C>) -> Getter<S, C>
Parameters
other
Value to compose with.
Return Value
A
Getter
resulting from the sequential application of both optics. -
Obtains the focus if it matches a predicate.
Declaration
Swift
public func find(_ s: S, _ predicate: (A) -> Bool) -> Option<A>
Parameters
s
Source.
predicate
Testing predicate.
Return Value
An optional value that is present if the focus matches the predicate, or empty otherwise.
-
Checks if the focus matches a predicate.
Declaration
Swift
public func exists(_ s: S, _ predicate: (A) -> Bool) -> Bool
Parameters
s
Source.
predicate
Testing predicate.
Return Value
A boolean value indicating if the focus matches the predicate.
-
Focuses on a specific index of this getter.
Declaration
Swift
func at(_ i: A.AtIndex) -> Getter<S, A.AtFoci>
Parameters
i
Index to focus.
Return Value
A getter from this structure to the focused index.
-
Provides an identity
Getter
.Declaration
Swift
static var identity: Getter<S, S> { get }
-
Provides a
Getter
that takes eitherS
orS
and strips the choice ofS
.Declaration
Swift
static var codiagonal: Getter<Either<S, S>, S> { get }