[Pitch] Introduce Expanded Parameters

I love the idea but think the pitch is just a little too far-reaching as-is*.

It would help if we could all understand the motivation for why the linearGradient methods you've mentioned exist.

That's my understanding as well. The static methods are only discoverability aids, emulating the usability of enumerations. (See ShapeStyle).

And if not for that, they'd only be initializers, not static "factory" methods.


Employing more factory methods is the direction the language is going in right now. So I think the solution is to just make that easier.

public extension ShapeStyle where Self == LinearGradient {
  // Creates an alias for all LinearGradient initializer overloads
  @factory static func linearGradient
}

I don't think factory is the best word, but it is a historical term of art.


And I don't know that we need this flexibility, but there are probably use cases for when the returned type is not Self:

public extension ShapeStyle where Self == LinearGradient {
  // Creates an alias for all AnotherType initializer overloads
  @factory(AnotherType) static func anotherType
}

I might be interested in being able to opaque the instances returned from these sorts of methods, e.g.

@factory static func mysteriousInstance -> some PublicProtocol

…but because of the way we're organizing these things now, there's no utility in that. The public methods can't be available unless the concrete types are public.

// Extension cannot be declared public because its generic requirement uses an internal type
public extension PublicProtocol where Self == InternalType {
  // Cannot declare a public static property in an extension with internal requirements
  @factory public static func mysteriousInstance -> some PublicProtocol
}

You could get around this with the previous parameter syntax, but you'd still have to put this method somewhere, and it can't be in an extension that relies on InternalType. :pensive:

@factory(InternalType) public static func mysteriousInstance -> some PublicProtocol

(* Specifically, I think trying to automate the invisibling of more than one init call is too complex.)

1 Like