Sum

public final class Sum<F, G, V> : SumOf<F, G, V>

The Sum type models a Comonad that contains two different Comonadic values, where only one of them can be selected at a given moment.

  • Left side of this value.

    Declaration

    Swift

    public let left: Kind<F, V>
  • Right side of this value.

    Declaration

    Swift

    public let right: Kind<G, V>
  • Selected side.

    Declaration

    Swift

    public let side: Side
  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ value: SumOf<F, G, V>) -> Sum<F, G, V>

    Parameters

    value

    Value in the higher-kind form.

    Return Value

    Value cast to Sum.

  • Constructs a Sum value selecting the left side.

    Declaration

    Swift

    public static func left(_ left: Kind<F, V>, _ right: Kind<G, V>) -> Sum<F, G, V>

    Parameters

    left

    Left side of the Sum.

    right

    Right side of the Sum.

    Return Value

    The Sum of both values, with left selected.

  • Constructs a Sum value selecting the right side.

    Declaration

    Swift

    public static func right(_ left: Kind<F, V>, _ right: Kind<G, V>) -> Sum<F, G, V>

    Parameters

    left

    Left side of the Sum.

    right

    Right side of the Sum.

    Return Value

    The Sum of both values, with right selected.

  • Initializes a Sum value.

    Declaration

    Swift

    public init(left: Kind<F, V>, right: Kind<G, V>, side: Side = .left)

    Parameters

    left

    Left side of the Sum.

    right

    Right side of the Sum.

    side

    Selected side of the Sum.

  • Changes the selected side.

    Declaration

    Swift

    public func change(side: Side) -> Sum<F, G, V>

    Parameters

    side

    New selected side.

    Return Value

    A new Sum with the same contents and the new selected side.

  • Converts this Sum to an EitherK.

    Declaration

    Swift

    public func lower() -> EitherK<F, G, V>

    Return Value

    An EitherK.left if the left side of the Sum is selected, or an EitherK.right otherwise.

  • Obtains the left side.

    Declaration

    Swift

    public func lowerLeft() -> Kind<F, V>

    Return Value

    Left side of the Sum.

  • Obtains the right side.

    Declaration

    Swift

    public func lowerRight() -> Kind<G, V>

    Return Value

    Right side of the Sum.

  • Extracts the value inside the comonadic value that is not selected.

    Declaration

    Swift

    func extractOther() -> V

    Return Value

    Value contained in the not selected comonadic value.