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

Specifying the error type E for type Result[T, E] + initializer #59

Open
radkomih opened this issue Jan 24, 2023 · 0 comments
Open

Specifying the error type E for type Result[T, E] + initializer #59

radkomih opened this issue Jan 24, 2023 · 0 comments
Labels
enhancement New feature or request scale

Comments

@radkomih
Copy link
Collaborator

radkomih commented Jan 24, 2023

Declarations of Option[T] and Result[T, E] value types can specify custom-defined types for T and E.

Example:

type MyOk struct {}
type MyError struct {}

...

buffer := &bytes.Buffer{}
Result[MyOk, MyError]{}.Encode(buffer)

Currently, DecodeResult relies on the convention that for each type there is a Decode<TypeName> function. It invokes the decode function only for the predefined types, not for custom-defined ones.

res := DecodeResult[MyOk, MyError](buffer)

We need to be able to dynamically build/call the corresponding decode function for the specified type using reflection.

Approach 1: Obtain the full package name of the corresponding function. We could potentially derive it from the Type. However, we'll rely on the convention that the decode function is defined in the same package.

Approach 2: Include a Decode method as part of the interface, so there will be type checks, and each type will have a Decode method that can be called using reflection.

Related #62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request scale
Projects
None yet
Development

No branches or pull requests

1 participant