Skip to content

feat: add Do / bind / let for Result and ResultAsync#680

Open
iwasa-kosui wants to merge 6 commits into
supermacro:masterfrom
iwasa-kosui:do-bind
Open

feat: add Do / bind / let for Result and ResultAsync#680
iwasa-kosui wants to merge 6 commits into
supermacro:masterfrom
iwasa-kosui:do-bind

Conversation

@iwasa-kosui

Copy link
Copy Markdown

Summary

  • Add Do + bind + let for both Result and ResultAsync
  • bind accumulates values from Result-returning functions, let from pure functions
  • Error types accumulate as union, consistent with andThen
  • ResultAsync.bind accepts both sync Result and ResultAsync

Closes #679

Usage

Result.Do()
  .bind("user", () => getUser(id))
  .bind("role", ({ user }) => getRole(user))
  .let("label", ({ user, role }) => `${user.name} (${role.name})`)
  .map(({ user, role, label }) => /* ... */)

Test plan

  • Runtime tests for Result.Do / bind / let (value accumulation, short-circuit, error propagation, chaining with map/andThen)
  • Runtime tests for ResultAsync.Do / bind / let (same cases + sync/async interop)
  • Type-level tests verifying accumulated types and error union inference
  • All existing tests pass (137 total)

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Add Do notation support for composing multiple dependent Result/ResultAsync
operations without nested closures.

- Result.Do() and ResultAsync.Do as entry points
- bind: accumulate values from Result-returning functions
- let: accumulate values from pure functions
- Error types accumulate as union, consistent with andThen
- ResultAsync.bind accepts both sync Result and ResultAsync

Closes supermacro#679

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@changeset-bot

changeset-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cffd363

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
neverthrow Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

iwasa-kosui and others added 4 commits June 23, 2026 01:54
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@iwasa-kosui iwasa-kosui marked this pull request as ready for review June 22, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Do + bind / let for Result and ResultAsync

1 participant