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 another `Getter`.

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 a `Lens`.

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 an `Iso`.

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.

• ``` +(_:_:) ```

Composes a `Getter` with a `Fold`.

Declaration

Swift

``public static func + <C>(lhs: Getter<S, A>, 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.

• ``` init(get:) ```

Initializes a Getter.

Declaration

Swift

``public init(get: @escaping (S) -> A)``

Parameters

 ``` get ``` Function to focus into a structure.
• ``` get(_:) ```

Obtains the focus for a given source.

Declaration

Swift

``public func get(_ s: S) -> A``

Parameters

 ``` s ``` Source.

Return Value

Focus.

• ``` choice(_:) ```

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.

• ``` split(_:) ```

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.

• ``` zip(_:) ```

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.

• ``` first() ```

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.

• ``` second() ```

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.

• ``` left() ```

Creates the sum of this `Getter` with another type, placing this as the left side.

Declaration

Swift

``public func left<C>() -> Getter<Either<S, C>, Either<A, C>>``

Return Value

A `Getter` that operates on `Either`s where the right side remains unchanged.

• ``` right() ```

Creates the sum of this `Getter` with another type, placing this as the right side.

Declaration

Swift

``public func right<C>() -> Getter<Either<C, S>, Either<C, A>>``

Return Value

A `Getter` that operates on `Either`s where the left side remains unchanged.

• ``` compose(_:) ```

Composes this `Getter` with a `Getter`.

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.

• ``` compose(_:) ```

Composes this `Getter` with a `Lens`.

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.

• ``` compose(_:) ```

Composes this `Getter` with an `Iso`.

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.

• ``` compose(_:) ```

Composes this `Getter` 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 both optics.

• ``` asFold ```

Converts this `Getter` into a `Fold`.

Declaration

Swift

``public var asFold: Fold<S, A> { get }``
• ``` find(_:_:) ```

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.

• ``` exists(_:_:) ```

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.

• ``` ask() ```

Extracts the value viewed through the get function.

Declaration

Swift

``public func ask() -> Reader<S, A>``

Return Value

A `Reader` from source to target.

• ``` toReader() ```

Extracts the value viewed through the get function.

Declaration

Swift

``public func toReader() -> Reader<S, A>``

Return Value

A `Reader` from source to target.

• ``` asks(_:) ```

Extracts the value viewed through the get function and applies the provided function to it.

Declaration

Swift

``public func asks<B>(_ f: @escaping (A) -> B) -> Reader<S, B>``

Parameters

 ``` f ``` Function to apply to the focus.

Return Value

A `Reader` from source to the target modified by the provided function.

• ``` extract() ```

Extracts the focus view through the `Getter`.

Declaration

Swift

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

Return Value

A `State` of the source and target.

• ``` toState() ```

Extracts the focus view through the `Getter`.

Declaration

Swift

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

Return Value

A `State` of the source and target.

• ``` extractMap(_:) ```

Extracts the focus view through the `Getter` and applies the provided function to it.

Declaration

Swift

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

Return Value

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

• ``` at(_:) ```

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.

• ``` identity ```

Provides an identity `Getter`.

Declaration

Swift

``static var identity: Getter<S, S> { get }``
• ``` codiagonal ```

Provides a `Getter` that takes either `S` or `S` and strips the choice of `S`.

Declaration

Swift

``static var codiagonal: Getter<Either<S, S>, S> { get }``