I think this could probably be handled in individual projects the way people normally provide commonly used strings, rather than trying to provide a specific API for this use case.
Agreed, that's the prior art I was using for this naming – I'll make sure to add a reference to that API to the proposal.
Thanks for sharing this exploration! I'm looking for a more specific solution, as pitched, but it definitely seems like there are other ways of enriching string interpolations.
I thought some more about this question, and I actually don't think there's a correct way to provide this more widely. StringInterpolationProtocol
defines a single requirement for appending, the one for literal segments: appendLiteral(Self.StringLiteralType)
. What kinds of types are allowed in the actual interpolations is dictated by the specific func appendInterpolation
overloads that a type implements. Since the proposed addition would add an overload that takes an optional version of any type T
, adding it straight to the protocol would automatically increase the number of types that were allowed in every string interpolatable type.
As such, it's only okay to add this addition to interpolation types where an unconstrained parameter is always accepted, like String
.