ComonadTraced

public protocol ComonadTraced : Comonad

The ComonadTraced type class represents those comonads which support relative (monoidal) position information.

  • Index type to access values inside the Comonad

    Declaration

    Swift

    associatedtype M
  • Extracts a value at the specified relative position.

    Declaration

    Swift

    static func trace<A>(_ wa: Kind<Self, A>, _ m: M) -> A

    Parameters

    wa

    Trace.

    m

    Relative position.

    Return Value

    Value corresponding to the specified position.

  • Gets a value that depends on the current position.

    Declaration

    Swift

    static func listens<A, B>(_ wa: Kind<Self, A>, _ f: @escaping (M) -> B) -> Kind<Self, (B, A)>

    Parameters

    wa

    Trace.

    f

    Function to compute a value from the current position.

    Return Value

    A tuple with the current and computed value in the context of this ComonadTraced.

  • Obtains a Trace that can modify the current position.

    Declaration

    Swift

    static func pass<A>(_ wa: Kind<Self, A>) -> Kind<Self, ((M) -> M) -> A>

    Parameters

    wa

    Trace.

    Return Value

    Trace that can modify the current position.

  • traces(_:_:) Extension method

    Extracts a value at a relative position which depends on the current value.

    Declaration

    Swift

    static func traces<A>(_ wa: Kind<Self, A>, _ f: @escaping (A) -> M) -> A

    Parameters

    wa

    Trace.

    f

    Function to compute the position based on the current value.

    Return Value

    Value corresponding to the new position.

  • listen(_:) Extension method

    Obtains the current position together with the current value.

    Declaration

    Swift

    static func listen<A>(_ wa: Kind<Self, A>) -> Kind<Self, (M, A)>

    Parameters

    wa

    Trace.

    Return Value

    A tuple with the current position and value in the context of this ComonadTraced.

  • censor(_:_:) Extension method

    Apply a function to the current position.

    Declaration

    Swift

    static func censor<A>(_ wa: Kind<Self, A>, _ f: @escaping (M) -> M) -> Kind<Self, A>

    Parameters

    wa

    Trace.

    f

    Function to transform the current position.

    Return Value

    Trace focused in the new position.