Skip to content

Feature requests: convenience helpers and improved spec compliance #6

Description

@aaronhuggins

Some features that I'd like to contribute from my personal implementation that this one is missing. Opening issue for discussion before just opening a pull request to help eliminate unnecessary work. Some of these are convenience, some of these bring the implementations closer to the Rust spec. Porting these is little effort, as the code already exists in my own personal work.

Convenience helpers

  • function fromPromise<V, E extends Error>(promise: Promise<V>): Promise<Result<V, E>>; avoids additional microtasks
  • function fromSync<V, E extends Error>(func: () => V): Result<V, E>; synchronous helper, avoids microtasks completely
  • Symbol.toStringTag support; useful to quickly and easily distinguish resulting objects
  • Symbol.hasInstance support on Err, Ok, Some, None; example myResult instance of Err

Spec compliance

  • Iterable support, similar to class Result<T, E extends Error> implements Iterable<T>
  • Result.expectErr

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions