Skip to content

Introduce Builder-style syntax #1

@scottmatthewman

Description

@scottmatthewman

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions