Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper to convert option to result with transform #301

Open
joprice opened this issue Jan 8, 2025 · 1 comment · May be fixed by #303
Open

helper to convert option to result with transform #301

joprice opened this issue Jan 8, 2025 · 1 comment · May be fixed by #303
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@joprice
Copy link
Contributor

joprice commented Jan 8, 2025

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?

@TheAngryByrd
Copy link
Collaborator

Agreed! Seem like a good PR to have:

  • Add requireSomeWith and requireNoneWith
  • Add to Result, AsyncResult, TaskResult, JobResult
  • Add corresponding tests

@TheAngryByrd TheAngryByrd added enhancement New feature or request good first issue Good for newcomers labels Jan 8, 2025
@joprice joprice linked a pull request Jan 11, 2025 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants