Contravariant

public protocol Contravariant : Invariant

A Contravariant Functor is the dual of a Covariant Functor, usually referred to as just Functor. Whereas an intuition behind Covariant Functors is that they can be seen as containing or producing values, Contravariant Functors can be seen as consuming values.

  • Creates a new value transforming the type using the provided function, preserving the structure of the original type.

    Declaration

    Swift

    static func contramap<A, B>(_ fa: Kind<Self, A>, _ f: @escaping (B) -> A) -> Kind<Self, B>

    Parameters

    fa

    Value to be transformed.

    f

    Transforming function.

    Return Value

    The result of transforming the value type using the provided function, maintaining the structure of the original value.

  • imap(_:_:_:) Extension method

    Declaration

    Swift

    static func imap<A, B>(_ fa: Kind<Self, A>, _ f: @escaping (A) -> B, _ g: @escaping (B) -> A) -> Kind<Self, B>
  • contralift(_:) Extension method

    Given a function, provides a new function lifted to the context type implementing this instance of Contravariant, but reversing the direction of the arrow.

    Declaration

    Swift

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

    Parameters

    f

    Function to be lifted.

    Return Value

    Function in the context implementing this instance.