Ior

public final class Ior<A, B> : IorOf<A, B>

Ior represents an inclusive-or of two different types. It may have a value of the left type, the right type or both at the same time.

  • Creates an Ior value of the left type.

    Declaration

    Swift

    public static func left(_ a: A) -> Ior<A, B>

    Parameters

    a

    A value of the left type.

    Return Value

    An Ior of the left type.

  • Creates an Ior value of the right type.

    Declaration

    Swift

    public static func right(_ b: B) -> Ior<A, B>

    Parameters

    b

    A value of the right type.

    Return Value

    An Ior of the right type.

  • Creates an Ior value with both types.

    Declaration

    Swift

    public static func both(_ a: A, _ b: B) -> Ior<A, B>

    Parameters

    a

    A value of the left type.

    b

    A value of the right type.

    Return Value

    An Ior of both types.

  • Creates an Ior value from two optional values.

    Declaration

    Swift

    public static func fromOptions(_ ma: Option<A>, _ mb: Option<B>) -> Option<Ior<A, B>>

    Parameters

    ma

    An optional value of the left type.

    mb

    An optional value of the right type.

    Return Value

    An optional Ior that is empty if both options are empty, or has a present Ior with the present values of the options.

  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ fa: IorOf<A, B>) -> Ior<A, B>

    Parameters

    fa

    Value in the higher-kind form.

    Return Value

    Value cast to Ior.

  • Applies the provided closures based on the content of this Ior value.

    Declaration

    Swift

    public func fold<C>(_ fa: (A) -> C, _ fb: (B) -> C, _ fab: (A, B) -> C) -> C

    Parameters

    fa

    Closure to apply if the contained value in this Ior is a member of the left type.

    fb

    Closure to apply if the contained value in this Ior is a member of the right type.

    fab

    Closure to apply if the contained values in this Ior are members of both types.

    Return Value

    Result of aplying the corresponding closure to this value.

  • Checks if this value contains only a value of the left type.

    Declaration

    Swift

    public var isLeft: Bool { get }
  • Checks if this value contains only a value of the right type.

    Declaration

    Swift

    public var isRight: Bool { get }
  • Checks if this value contains values of both left and right types.

    Declaration

    Swift

    public var isBoth: Bool { get }
  • Transforms both type parameters with the provided closures.

    Declaration

    Swift

    public func bimap<C, D>(_ fa: (A) -> C, _ fb: (B) -> D) -> Ior<C, D>

    Parameters

    fa

    Closure to transform the left type.

    fb

    Closure to transform the right type.

    Return Value

    An Ior value with its type parameters transformed using the provided functions.

  • Transforms the left type parameter with the provided closure.

    Declaration

    Swift

    public func mapLeft<C>(_ f: (A) -> C) -> Ior<C, B>

    Parameters

    f

    Transforming function.

    Return Value

    An Ior value with its left type parameter transformed using the provided function.

  • Swaps the type parameters.

    Declaration

    Swift

    public func swap() -> Ior<B, A>

    Return Value

    An Ior where the left values are right and vice versa, and both values are swapped.

  • Transforms this Ior to nested Either values representing the possible values wrapped.

    Declaration

    Swift

    public func unwrap() -> Either<Either<A, B>, (A, B)>

    Return Value

    A value where:

    • Ior.left is mapped to Either.left(Either.left).
    • Ior.right is mapped to Either.left(Either.right).
    • Ior.both is mapped to Either.right containing a tuple of the two values.

  • Obtains a tuple of optional values with the values wrapped in this Ior.

    Declaration

    Swift

    public func pad() -> (Option<A>, Option<B>)

    Return Value

    A tuple of optional values that are present or absent based on the contents of this Ior.

  • Converts this Ior to an Either.

    Declaration

    Swift

    public func toEither() -> Either<A, B>

    Return Value

    An Either value with a direct mapping of the left and right cases, and mapping the both case to a right value (losing the left value).

  • Converts this Ior to an Option.

    Declaration

    Swift

    public func toOption() -> Option<B>

    Return Value

    An Option of the right type, discarding any left value in this Ior.

  • Obtains a value of the right type, or a default if there is none.

    Declaration

    Swift

    public func getOrElse(_ defaultValue: B) -> B

    Parameters

    defaultValue

    Default value for the left case.

    Return Value

    Right value wrapped in the right and both cases, or the default value if this Ior contains a left value.

  • Provides an Iso to go from/to this type to its Kind version.

    Declaration

    Swift

    static var fixIso: Iso<Ior<A, B>, IorOf<A, B>> { get }
  • Provides a Fold based on the Foldable instance of this type.

    Declaration

    Swift

    static var fold: Fold<Ior<A, B>, B> { get }
  • Provides a Traversal based on the Traverse instance of this type.

    Declaration

    Swift

    static var traversal: Traversal<Ior<A, B>, B> { get }
  • Undocumented

    Declaration

    Swift

    public typealias EachFoci = B
  • Declaration

    Swift

    public static var each: Traversal<Ior<A, B>, B> { get }
  • Provides a prism focused on the left side of this Ior.

    Declaration

    Swift

    static var leftPrism: Prism<Ior<A, B>, A> { get }
  • Provides a prism focused on the right side of this Ior.

    Declaration

    Swift

    static var rightPrism: Prism<Ior<A, B>, B> { get }
  • Provides a prism focused on the both side of this Ior.

    Declaration

    Swift

    static var bothPrism: Prism<Ior<A, B>, (A, B)> { get }
  • Declaration

    Swift

    public var description: String { get }