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

[Discussion/refactor/rocks-lib] expose builders for operations #293

Open
mrcjkb opened this issue Dec 31, 2024 · 0 comments
Open

[Discussion/refactor/rocks-lib] expose builders for operations #293

mrcjkb opened this issue Dec 31, 2024 · 0 comments

Comments

@mrcjkb
Copy link
Member

mrcjkb commented Dec 31, 2024

Functions like operations::install take parameters that are often instantiated using a default value.
Perhaps we can use builders instead. This could make the API more flexible, allowing us to add optional arguments without it being a breaking change.

For example, operations::install could look like this:

Installer::new()
  .packages(...)
  .package_db(...)
  .config(...)
  .pin(...)
  .install()

Bonus: Since there are non-optional parameters, we could implement type-safe curried builders, where the types would look like this:

Installer::new() // => Installer
  .packages(...) // => InstallerWithPackages
  .package_db(...) // => InstallerWithPackageDB
  .config(...) // => InstallerReady
  .pin(...) // => InstallerReady (pin and progress are optional)
  .install()

Or, not as pretty, but simpler, with less boilerplate:

Installer::new(packages, package_db, conifg)
  .pin(...)
  .install()

In this example, all arguments could be optional (config has a default, package_db can be instantiated from a default config, packages can be empty...)

@vhyrro, what are your thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant