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<A>.

  • 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>
  • 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.

  • Safe downcast to Option<A>.

    Declaration

    Swift

    public static func fix(_ fa: OptionOf<A>) -> Option<A>
  • 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.

  • 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.

  • 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.

  • 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.

  • 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.

  • 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.

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

    Declaration

    Swift

    public func toOptional() -> A?
  • Converts this option into an empty array, if absent, or a singleton array, if present.

    Declaration

    Swift

    public func toArray() -> [A]
  • 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 var debugDescription: String { get }
  • Undocumented

    Declaration

    Swift

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

    Declaration

    Swift

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