Option

public final class Option<A> : OptionOf<A>

Represents optional values. Instances of this type may represent the presence of a value (some) or absence of it (none). This type is isomorphic to native Swift Optional<A> (usually written A?), with the addition of behaving as a Higher Kinded Type.

  • Constructs an instance of Option with presence of a value of the type parameter.

    It is an alias for Option<A>.pure(_:)

    Declaration

    Swift

    public static func some(_ a: A) -> Option<A>

    Parameters

    a

    Value to be wrapped in an Option.

    Return Value

    An option wrapping the value passed as an argument.

  • Constucts an instance of Option with absence of a value.

    It is an alias for Option<A>.empty()

    Declaration

    Swift

    public static func none() -> Option<A>

    Return Value

    An option with no present value

  • Converts a native Swift optional into a value of Option<A>.

    Declaration

    Swift

    public static func fromOptional(_ a: A?) -> Option<A>

    Parameters

    a

    Optional value to be converted.

    Return Value

    An Option with the same structure as the argument.

  • Safe downcasting.

    Declaration

    Swift

    public static func fix(_ fa: OptionOf<A>) -> Option<A>

    Parameters

    fa

    Option in higher-kind form.

    Return Value

    Value cast to Option.

  • Applies a function based on the presence or absence of a value.

    Declaration

    Swift

    public func fold<B>(_ ifEmpty: () -> B, _ f: (A) -> B) -> B

    Parameters

    ifEmpty

    A closure that is executed when there is no value in the Option.

    f

    A closure that is executed where there is a value in the Option. In such case, the the inner value is sent as an argument of f.

    Return Value

    Result of applying the corresponding closure based on the value of this object.

  • Applies a predicate to the wrapped value of this option, returning it if the value does not match the predicate, or none otherwise.

    Declaration

    Swift

    public func filterNot(_ predicate: @escaping (A) -> Bool) -> Kind<ForOption, A>

    Parameters

    predicate

    Boolean predicate to test the wrapped value.

    Return Value

    This value if it does not match the predicate, or none otherwise.

  • Obtains the wrapped value, or a default value if absent.

    Declaration

    Swift

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

    Parameters

    defaultValue

    Value to be returned if this option is empty.

    Return Value

    The value wrapped in this Option, if present, or the value provided as an argument, otherwise.

  • Obtains the wrapped value, or a default value if absent.

    Declaration

    Swift

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

    Parameters

    defaultValue

    Closure to be evaluated if there is no wrapped value in this option.

    Return Value

    The value wrapped in this Option, if present, or the result of running the closure provided as an argument, otherwise.

  • Obtains this option, or a default value if this option is empty.

    Declaration

    Swift

    public func orElse(_ defaultValue: Option<A>) -> Option<A>

    Parameters

    defaultValue

    Default option value to be returned if this option is empty.

    Return Value

    This option, if has a present value, or the value provided as an argument, otherwise.

  • Obtains this option, or a default value if this option is empty.

    Declaration

    Swift

    public func orElse(_ defaultValue: () -> Option<A>) -> Option<A>

    Parameters

    defaultValue

    Closure returning an option for the empty case.

    Return Value

    This option, if has a present value, or the result of running the closure provided as an argument, otherwise.

  • Converts this option into a native Swift optional A?.

    Declaration

    Swift

    public func toOptional() -> A?

    Return Value

    A Swift Optional with the same structure as this value.

  • Converts this option into an array.

    Declaration

    Swift

    public func toArray() -> [A]

    Return Value

    An empty array if this value is absent, or a singleton array, if present.

  • Undocumented

    Declaration

    Swift

    public static func toPOption<B>() -> PIso<Option<A>, Option<B>, A?, B?>
  • Undocumented

    Declaration

    Swift

    public static func toOption() -> Iso<Option<A>, A?>
  • Undocumented

    Declaration

    Swift

    public static func PSomePrism<B>() -> PPrism<Option<A>, Option<B>, A, B>
  • Undocumented

    Declaration

    Swift

    public static func somePrism() -> Prism<Option<A>, A>
  • Undocumented

    Declaration

    Swift

    public static func nonePrism() -> Prism<Option<A>, ()>
  • Undocumented

    Declaration

    Swift

    public static func toPEither<B>() -> PIso<Option<A>, Option<B>, Either<(), A>, Either<(), B>>
  • Undocumented

    Declaration

    Swift

    public static func toEither() -> Iso<Option<A>, Either<(), A>>
  • Declaration

    Swift

    public var description: String { get }
  • Declaration

    Swift

    public func combine(_ other: Option<A>) -> Option<A>