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.

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

  • 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 Eithers where the right side remains unchanged.

  • 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 Eithers where the left side remains unchanged.

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

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

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

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

  • Converts this Getter into a Fold.

    Declaration

    Swift

    public var asFold: Fold<S, A> { get }
  • 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.

  • Extracts the value viewed through the get function.

    Declaration

    Swift

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

    Return Value

    A Reader from source to target.

  • Extracts the value viewed through the get function.

    Declaration

    Swift

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

    Return Value

    A Reader from source to target.

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

  • Extracts the focus view through the Getter.

    Declaration

    Swift

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

    Return Value

    A State of the source and target.

  • Extracts the focus view through the Getter.

    Declaration

    Swift

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

    Return Value

    A State of the source and target.

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

  • 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 either S or S and strips the choice of S.

    Declaration

    Swift

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