# Coproduct4

``public final class Coproduct4<A, B, C, D> : Coproduct4Of<A, B, C, D>``

Represents a sum type of 4 different types.

• ``` first(_:) ```

Creates an instance of a coproduct providing a value of the first type.

#### Declaration

Swift

``public static func first(_ a: A) -> Coproduct4<A, B, C, D>``

#### Parameters

 ``` a ``` Value of the first type of the coproduct.

#### Return Value

A coproduct with a value of the first type.

• ``` second(_:) ```

Creates an instance of a coproduct providing a value of the second type.

#### Declaration

Swift

``public static func second(_ b: B) -> Coproduct4<A, B, C, D>``

#### Parameters

 ``` b ``` Value of the second type of the coproduct.

#### Return Value

A coproduct with a value of the second type.

• ``` third(_:) ```

Creates an instance of a coproduct providing a value of the third type.

#### Declaration

Swift

``public static func third(_ c: C) -> Coproduct4<A, B, C, D>``

#### Parameters

 ``` c ``` Value of the third type of the coproduct.

#### Return Value

A coproduct with a value of the third type.

• ``` fourth(_:) ```

Creates an instance of a coproduct providing a value of the fourth type.

#### Declaration

Swift

``public static func fourth(_ d: D) -> Coproduct4<A, B, C, D>``

#### Parameters

 ``` d ``` Value of the fourth type of the coproduct.

#### Return Value

A coproduct with a value of the fourth type.

• ``` fold(_:_:_:_:) ```

Applies a function depending on the content of the coproduct.

#### Declaration

Swift

``````public func fold<Z>(_ fa: (A) -> Z,
_ fb: (B) -> Z,
_ fc: (C) -> Z,
_ fd: (D) -> Z) -> Z``````

#### Parameters

 ``` fa ``` Function to apply with a value of the first type. ``` fb ``` Function to apply with a value of the second type. ``` fc ``` Function to apply with a value of the third type. ``` fd ``` Function to apply with a value of the fourth type.

#### Return Value

A value resulting of the application of the corresponding function based on the content of the coproduct.

• ``` first ```

Retrieves the value of the first type, if present.

#### Declaration

Swift

``public var first: Option<A> { get }``
• ``` second ```

Retrieves the value of the second type, if present.

#### Declaration

Swift

``public var second: Option<B> { get }``
• ``` third ```

Retrieves the value of the third type, if present.

#### Declaration

Swift

``public var third: Option<C> { get }``
• ``` fourth ```

Retrieves the value of the fourth type, if present.

#### Declaration

Swift

``public var fourth: Option<D> { get }``