Skip to content

Add requireSomeWith and requireNoneWith for lazy error evaluation#352

Merged
TheAngryByrd merged 3 commits intomasterfrom
copilot/add-require-some-with-helper
Feb 25, 2026
Merged

Add requireSomeWith and requireNoneWith for lazy error evaluation#352
TheAngryByrd merged 3 commits intomasterfrom
copilot/add-require-some-with-helper

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 25, 2026

  • Add requireSomeWith and requireNoneWith to Result.fs
  • Add requireSomeWith and requireNoneWith to AsyncResult.fs
  • Add requireSomeWith and requireNoneWith to TaskResult.fs
  • Add requireSomeWith and requireNoneWith to JobResult.fs (JobResult project)
  • Add tests for all four modules
  • Add gitbook documentation in result/requireFunctions.md
  • Add gitbook documentation in asyncResult/others.md
  • Add gitbook documentation in taskResult/others.md
  • Add gitbook documentation in jobResult/others.md
Original prompt

This section details on the original issue you should resolve

<issue_title>helper to convert option to result with transform</issue_title>
<issue_description>I may have overlooked a helper in either this or the standard library, but I end up finding this function useful, similar to requireSome but where the fallback is evaluated on demand.

let fromOption f = (unit -> 'a) -> option<'b> -> Result<'b,'a> 
      function
      | Some value -> Ok value
      | None -> Error(f ())

Is there an equivalent or would it make sense to add perhaps Result.requireSomeWith?</issue_description>

Comments on the Issue (you are @copilot in this section)

@TheAngryByrd Agreed! Seem like a good PR to have:
  • Add requireSomeWith and requireNoneWith
  • Add to Result, AsyncResult, TaskResult, JobResult
  • Add corresponding tests</comment_new>

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…t, TaskResult, and JobResult

Co-authored-by: TheAngryByrd <1490044+TheAngryByrd@users.noreply.github.com>
Copilot AI changed the title [WIP] Add requireSomeWith helper for Result type Add requireSomeWith and requireNoneWith for lazy error evaluation Feb 25, 2026
Copilot AI requested a review from TheAngryByrd February 25, 2026 02:52
@TheAngryByrd TheAngryByrd requested a review from Copilot February 25, 2026 03:05
Copy link
Copy Markdown
Collaborator

@TheAngryByrd TheAngryByrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot add or update gitbook documentation

Co-authored-by: TheAngryByrd <1490044+TheAngryByrd@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 25, 2026

@copilot add or update gitbook documentation

Done in a39b1da. Added requireSomeWith and requireNoneWith entries to:

  • gitbook/result/requireFunctions.md
  • gitbook/asyncResult/others.md
  • gitbook/taskResult/others.md
  • gitbook/jobResult/others.md

@TheAngryByrd TheAngryByrd marked this pull request as ready for review February 25, 2026 03:09
Copilot AI requested a review from TheAngryByrd February 25, 2026 03:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds lazy evaluation variants requireSomeWith and requireNoneWith to defer error construction until it's actually needed, providing performance benefits when error messages are expensive to compute.

Changes:

  • Added requireSomeWith and requireNoneWith functions to Result, AsyncResult, TaskResult, and JobResult modules with [<InlineIfLambda>] for zero-cost abstraction
  • Added comprehensive test coverage for all implementations covering happy path and error path scenarios

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/FsToolkit.ErrorHandling/Result.fs Core implementation with XML documentation for requireSomeWith and requireNoneWith functions
src/FsToolkit.ErrorHandling/AsyncResult.fs Async wrapper delegating to Result module implementations
src/FsToolkit.ErrorHandling/TaskResult.fs Task wrapper delegating to Result module implementations
src/FsToolkit.ErrorHandling.JobResult/JobResult.fs Job wrapper delegating to Result module implementations
tests/FsToolkit.ErrorHandling.Tests/Result.fs Test coverage for Result module with happy/error path tests and integration into test suite
tests/FsToolkit.ErrorHandling.Tests/AsyncResult.fs Test coverage for AsyncResult module with async test cases and integration
tests/FsToolkit.ErrorHandling.Tests/TaskResult.fs Test coverage for TaskResult module with task test cases and integration
tests/FsToolkit.ErrorHandling.JobResult.Tests/JobResult.fs Test coverage for JobResult module with proper [<Tests>] attributes and integration

@TheAngryByrd TheAngryByrd merged commit 1c6f444 into master Feb 25, 2026
26 checks passed
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot

Remove AutoGPT subproject reference
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot

Remove AutoGPT subproject reference
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot

Remove AutoGPT subproject reference
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.

helper to convert option to result with transform

3 participants