Coproduct2

public final class Coproduct2<A, B> : Coproduct2Of<A, B>

Represents a sum type of 2 different types.

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

    Declaration

    Swift

    public static func first(_ a: A) -> Coproduct2<A, B>

    Parameters

    a

    Value of the first type of the coproduct.

    Return Value

    A coproduct with a value of the first type.

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

    Declaration

    Swift

    public static func second(_ b: B) -> Coproduct2<A, B>

    Parameters

    b

    Value of the second type of the coproduct.

    Return Value

    A coproduct with a value of the second type.

  • Applies a function depending on the content of the coproduct.

    Declaration

    Swift

    public func fold<Z>(_ fa: (A) -> Z,
                        _ fb: (B) -> 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.

    Return Value

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

  • Retrieves the value of the first type, if present.

    Declaration

    Swift

    public var first: Option<A> { get }
  • Retrieves the value of the second type, if present.

    Declaration

    Swift

    public var second: Option<B> { get }