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

Introduce Builder-style syntax #1

Open
scottmatthewman opened this issue Jan 2, 2024 · 0 comments
Open

Introduce Builder-style syntax #1

scottmatthewman opened this issue Jan 2, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@scottmatthewman
Copy link
Owner

Currently, CSV tables are defined as in the following example:

let table = CSVTable<Person>(
  columns: [
    CSVColumn("ID", \.id),
    CSVColumn("Name", \.name),
    // etc.
  ],
  configuration: .default
)

This isn't great for situations where I might need a more dynamic approach to column inclusion. For example, only users with a certain level of access may have access to personally sensitive information and their CSVs shouldn't attempt to include those columns. Or, I may have a feature in the app that is governed by a feature flag, and columns should be omitted if that flag is not on.

Another approach would be to use a ResultBuilder-style syntax for building table definitions, say:

CSVTable(configuration: .default) {
  Column("ID", \.id)
  Column("Name", \.name)
  if currentUser.isSuperAdmin {
    Column("Address", \.postalAddress)
    Column("Tel", \.telephone)
  }
  if FeatureSet.includes(.starRatings) {
    Column("Star rating") { StarRating($0.value) }
  }
}

This might also allow for configuration to be broken up and implemented as modifiers:

CSVTable {
  Column("ID", \.id)
  Column("Date of birth", \.date)
    .dateFormat(.iso8601)
}
.fieldDelimiter(.tab)
@scottmatthewman scottmatthewman added the enhancement New feature or request label Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant