This is what I got so far.
I don't know how to express "the Dependencies of each MiddlewareReader should be the same"
extension MiddlewareReaderProtocol {
public static func zip<each M: MiddlewareReaderProtocol, MOutput: MiddlewareProtocol>(
_ readers: repeat each M,
with map: @escaping @Sendable (repeat (each M).MiddlewareType) -> MOutput
) -> MiddlewareReader<M[0].Dependencies, MOutput> // Error: Array types are now written with the brackets around the element type
where (repeat (M.Dependencies == M[0].Dependencies)) {
MiddlewareReader { environment in
map((repeat each readers).inject(environment))
}
}
}
What might work is adding a generic to your zip function for the Dependencies type. and then adding M.Dependencies == Dependencies to the where clause. I've not tried it myself. Hope that works!
extension MiddlewareReaderProtocol {
public static func zip<each M: MiddlewareReaderProtocol, MOutput: MiddlewareProtocol, Dependencies>(
_ readers: repeat each M,
with map: @escaping @Sendable (repeat (each M).MiddlewareType) -> MOutput
) -> MiddlewareReader<Dependencies, MOutput>
where M.Dependencies == Dependencies {
MiddlewareReader { environment in
map((repeat each readers).inject(environment))
}
}
}
First, you need to "-enable-experimental-feature SameElementRequirements". Second, you should add a dummy generic parameter as an anchor for your constraints.
Be advised the implementation of this feature is incomplete. There are several code paths that still need updating to take same-element requirements into account, so less trivial examples won’t work.