I have found a use for
ExpressibleByKeyPathLiteral. It is a little complicated to explain, but I’ll try to summarize.
Let’s say we have some data, and we want to sort it first by one property, then another, and so forth. We could write a variadic
sort function to do so, and at the call-side it might look like this:
var pets: [Animal] = ... pets.sort(\.age, \.weight, \.name)
But we can’t make that work today since we don’t have variadic generics.
What we can do, however, is this:
pets.sort(.by(\.age), .by(\.weight), .by(\.name))
I have written a proof-of-concept implementation, and it works. Indeed, it works generically for any type, and variadically for any number of keypaths, and it works in Swift today even without variadic generics.
However, it would be nice to be able to just write the keypath literal, rather than having to wrap it in
.by(). Thus, I have a non-trivial use-case for