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

Add monoids for options #75

Closed
akshayjshah opened this issue Feb 17, 2022 · 4 comments
Closed

Add monoids for options #75

akshayjshah opened this issue Feb 17, 2022 · 4 comments

Comments

@akshayjshah
Copy link
Member

akshayjshah commented Feb 17, 2022

I think we should let users remix options. It's hard to do this from outside connect because the options interfaces have unexported functions.

func WithOptions(...Option) Option
func WithClientOptions(...ClientOption) ClientOption
func WithHandlerOptions(...HandlerOption) HandlerOption
@akshayjshah akshayjshah added this to the Connect Launch milestone Mar 3, 2022
akshayjshah added a commit that referenced this issue Mar 5, 2022
Add a way for users to compose multiple options into one.

Fixes #75.
@bufdev
Copy link
Member

bufdev commented Mar 5, 2022

What is the purpose of this? I don't immediately get it

@akshayjshah
Copy link
Member Author

Imagine your organization (like Buf!) has a standard collection of options that you'd like every handler, client, or both to use. Without this, you end up with a fairly unpleasant set of APIs: StandardClientOptions() []connect.ClientOption, etc., and users are constantly appending to slices and splatting them again.

client, err := NewFooClient(...,
  append(someorg.StandardClientOptions(),
    SomeSpecificOption(),
    SomeOtherOneOffOption(),
  )...,
)

With these functions, life's a bit nicer. someorg.StandardClientOptions can bundle a bunch of options into a single connect.ClientOption, and the user code ends up like this:

client, err := NewFooClient(...,
  someorg.StandardClientOptions(),
  someorg.UnusualOption(),
  MyOneOffOption(),
)

Ultimately, it's convenient for users to be able to make a single option have multiple effects. More or less, this is the same reason your proposal to build a multi-plugin for protoc/buf is nicer than forcing every tool to take a list of plugins to generate into the same directory.

@akshayjshah
Copy link
Member Author

Examples from other packages I've worked on:

Both of those options ended up pretty widely used, and the fx one in particular was a cornerstone of the whole ecosystem.

@bufdev
Copy link
Member

bufdev commented Mar 7, 2022

I'm not sure this will be as used in the connect world and it just adds to the number of types, but you feel strongly about it and it's fine with me. I might say that WithOptions confuses me a bit as opposed to something signaling this is a union of options like (and not suggesting this directly) but MultiOption

akshayjshah added a commit that referenced this issue Mar 7, 2022
Add a way for users to compose multiple options into one.

Fixes #75.
akshayjshah added a commit that referenced this issue Jul 26, 2023
Add a way for users to compose multiple options into one.

Fixes #75.
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

2 participants