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

Proposal: Optional results #145

Open
ngehrsitz opened this issue Nov 19, 2024 · 0 comments
Open

Proposal: Optional results #145

ngehrsitz opened this issue Nov 19, 2024 · 0 comments

Comments

@ngehrsitz
Copy link

There are tasks where not having a result is not the error case. For these cases I propose extending the set of Pools with

type OptionalResultPool[T any] struct {}
func (p *OptionalResultPool[T]) Go(f func() *T) {}
func (p *OptionalResultPool[T]) Wait() []T {}

type OptionalResultErrorPool[T any] struct {
func (p *OptionalResultErrorPool[T]) Go(f func() (*T, error)) {}
func (p *OptionalResultErrorPool[T]) Wait() ([]T, error) {}

type OptionalResultContextPool[T any] struct {}
func (p *OptionalResultContextPool[T]) Go(f func(context.Context) (*T, error)) {}
func (p *OptionalResultContextPool[T]) Wait() ([]T, error) {}

Wait() would then discard all nil results without an error and dereference the pointers.
The alternative to this that I am currently using is a wrapper type, that I then filter and map to the original type, but a native solution would be preferable.
Should I open a PR for this?

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