vojtamolda / Plotly.swift

Interactive data visualization library for Swift
https://vojtamolda.github.io/Plotly.swift/
MIT License
82 stars 8 forks source link

Consolidate variety of ArrayOr... types into a single generic #3

Closed vojtamolda closed 4 years ago

vojtamolda commented 4 years ago

There's a large variety of ArrayOr... types. They implement Plotly schema primitives that allow assignemnt of either a single value or an array of values. This is very simple in JavaScript due to lack of strong typing but requires a specialized data type in Swift.

Here's a list of the types that currently exist:

These types duplicate a lot of boilerplate code between each other. It's worthwhile investigating a possibility of replacing them with a single generic ArrayOr<Type> type. Ideally, this type would be as transparent as possible to users and should allow initialization from all meaningful literals via conformance the ExpressibleBy...Literal protocols from the standard library.

Potential pitfall is that a particular type can only conform to a protocol once. Even in cases with different conditional conformance. This would mean that only one of the specialized Type cases would be expressible for example by an Int literal even tough both ArrayOrInt and ArrayOrDouble could meaningfully benefit from it.

vojtamolda commented 4 years ago

Done!