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

feat: add castResult function #134

Closed
wants to merge 14 commits into from
Closed

feat: add castResult function #134

wants to merge 14 commits into from

Conversation

aleclarson
Copy link
Member

@aleclarson aleclarson commented Jul 22, 2024

Tip

The owner of this PR can publish a preview release by commenting /publish in this PR. Afterwards, anyone can try it out by running pnpm add radashi@pr<PR_NUMBER>.

Summary

Add a castResult function for coercing an (error, value) pair into a Result tuple (introduced by #132).

  • The CastResult type is used in the castResult function's return type.
  • Type tests are included (it was hard to cover all the edge cases!)

Related issue, if any:

Merge #132 first!

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed

Does this PR introduce a breaking change?

No

Bundle impact

Status File Size Difference (%)
M src/async/defer.ts 686 1 +259 (+60%)
M src/async/parallel.ts 1493 +259 (+20%)
M src/async/tryit.ts 502 +259 (+106%)
A src/function/castResult.ts 409 +409
A src/typed/isResult.ts 193 +193

Footnotes

  1. Function size includes the import dependencies of the function.

@aleclarson aleclarson added the new feature This PR adds a new function or extends an existing one label Jul 23, 2024
@aleclarson aleclarson changed the title feat: add toResult function feat: add castResult function Jul 29, 2024
@aleclarson
Copy link
Member Author

Closing this. The use cases are too limited, I think, and it adds unnecessary bloat to the other functions I tried using it in. I considered splitting the promise-handling into a new castResultPromise function, but then both castResult and castResultPromise started to look too much like syntax sugar.

That said, I'll be refactoring the types of tryit to use the new Result types introduced in #132.

@aleclarson aleclarson closed this Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This PR adds a new function or extends an existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant