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(result): add Result.unwrapRaw #475

Merged
merged 3 commits into from Oct 1, 2022
Merged

feat(result): add Result.unwrapRaw #475

merged 3 commits into from Oct 1, 2022

Conversation

favna
Copy link
Member

@favna favna commented Sep 30, 2022

This is essentially a shortcut for:

	return result.match({
		err: (error) => {
			throw error;
		},
		ok: (value) => value.data[0]
	});

which can then be written as:

return result.map((value) => value.data[0]).unwrapRaw();

This is useful when instead of throwing a ResultError you want to instead throw the inner error (i.e. ArgumentError for Sapphire, see sapphiredev/framework#528, or a FetchError from @skyra/safe-fetch, something that brought about this change)

packages/result/tests/Result.test.ts Outdated Show resolved Hide resolved
packages/result/tests/Result.test.ts Outdated Show resolved Hide resolved
packages/result/src/lib/Result/IResult.ts Show resolved Hide resolved
@favna favna merged commit 82fe79e into main Oct 1, 2022
@favna favna deleted the feat/result-add-unwrapraw branch October 1, 2022 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants