Appending PartialKeyPath to KeyPath

Why is there no .appending(path: PartialKeyPath<Tail>) -> PartialKeyPath function on the KeyPath<Root, Tail>?

When appending a PartialKeyPath<Tail> to a KeyPath you need to cast the KeyPath to either PartialKeyPath or AnyKeyPath first.

Curios. Adam.

Iā€™m not that familiar w/ keypath apis, but, KeyPath is already a (subclass of) PartialKeypath, right?

Thats correct, KeyPath is a subclass of PartialKeyPath.

I thought because the types being appended can be type-checked that it would have been possible to do this without needing to cast anything.

1 Like

Looking through the APIs, this might be a bug. There are myriad versions of appending(path:), and it seems the compiler keeps trying to use this one, when it actually should use one of these two: here, and here.

I was wondering if it's a bug, or if it's just missing the .appending(path: PartialKeyPath<>) implementation?

Either way, it would be helpful if this existed.

But at best, it'd return PartialKeyPath, something this one is already doing, no?

The appending methods from AnyKeyPath and PartialKeyPath are intentionally not available on concrete KeyPath<T, U> values, because they would type-check for mismatched KeyPath<T, U> and KeyPath<U', V> types and produce unwanted optionality. It looks like we are missing the operation to append a KeyPath<T, U> and PartialKeyPath<U> without forming an optional. I'd file a bug about that.

1 Like

Filed here:

1 Like

Don't you mean the missing signature to be:

KeyPath<Root, T>.appending(path: PartialKeyPath<T>) -> PartialKeyPath<Root>

or did I misunderstand something?

My mistake, fixed now. Thanks for letting me know :)

Terms of Service

Privacy Policy

Cookie Policy