# 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 ```

Left side of this value.

#### Declaration

Swift

``public let left: Kind<F, V>``
• ``` right ```

Right side of this value.

#### Declaration

Swift

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

Selected side.

#### Declaration

Swift

``public let side: Side``
• ``` fix(_:) ```

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.

• ``` left(_:_:) ```

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.

• ``` right(_:_:) ```

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.

• ``` init(left:right:side:) ```

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.
• ``` change(side:) ```

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.

• ``` lower() ```

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.

• ``` lowerLeft() ```

Obtains the left side.

#### Declaration

Swift

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

#### Return Value

Left side of the Sum.

• ``` lowerRight() ```

Obtains the right side.

#### Declaration

Swift

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

#### Return Value

Right side of the Sum.

• ``` extractOther() ```

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.