• v1.0.0-beta2 fad428a4e4

    v1, Beta 2 Pre-Release

    danieljsummers released this 2024-07-29 20:50:13 +00:00 | 4 commits to main since this release

    BREAKING CHANGE
    Option->is() has been renamed Option->contains() for consistency with Result (and any future collection implementation).

    FEATURES
    Both Option and Result now support:

    • bind: takes a callback that accepts the Some or OK value and returns an Option or Result, respectively. If the Option is None or the Result is Error, the callback will be skipped. This allows what is termed "railway-oriented programming" where every call is an opportunity to short-circuit the rest of the calls and return the Error result (or None).
    • contains: takes a value and an optional strict: parameter; it returns true if the Some or OK value matches the value provided, or false otherwise.
    • exists: takes a callback that accepts the Some or OK value and returns bool; None or Error results always return false.
    • toArray: converts a Some Option and an OK Result to a one-item array, and converts a None Option and an Error Result to an empty array.

    Additionally, Option now has a getOrThrow method that takes a callback that returns an Exception. If the Option is Some, the value is returned; if it is None, the callback is called and the resulting Exception is thrown.

    Downloads