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

use Maybe type for error handling (Fail case) #303

Open
unional opened this issue May 29, 2023 · 2 comments
Open

use Maybe type for error handling (Fail case) #303

unional opened this issue May 29, 2023 · 2 comments

Comments

@unional
Copy link
Owner

unional commented May 29, 2023

NumericStruct.Add<NumericStruct.FromNumeric<A, Fail>, NumericStruct.FromNumeric<B, Fail>>
//              ^ fail as input not accepting `Fail`

Instead of:

type NumericStruct.Add<A extends NumericStruct, B extends NumericStruct> ...

Accept Maybe<NumericStruct> and propagate the error.

This will simplify many implementation.

@unional
Copy link
Owner Author

unional commented May 29, 2023

Another thing to consider is how to add rich error processing.

i.e. instead of just pass down and up the error, we can process it.

e.g.

type Add<A, B> = DoWork<A, B> extends infer Result 
  ? Result extends FailBrand<unknown>
    ? `Cannot add '${A}` and `${B}` due to ${Result.message}`
    : Result
  : never

The idea is to use branding for fail case when do a brand check to see if the result is an error.

@unional
Copy link
Owner Author

unional commented Sep 13, 2023

This is partially addressed by the new case options, supporting $then/$else/$never and more.

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

No branches or pull requests

1 participant