Open IanKeen opened 6 years ago
Hey Ian, That's an interesting idea, thanks for sharing!
Am I understanding correctly that this approach doesn't distinguish between optional values being set to nil
and not being set at all?
hey @zapko , thats right! When you set an optional property to nil
it removes it from the underlying dictionary.
When you eventually come to extract the data if the target is optional this shouldn't matter since the generic type should define what data you want at the end.
So if a property should be non-optional and you don't give it a value in the partial data structure it will fail when you attempt to produce the 'real' model at the end.
Yeah, so if I want to calculate next step of a flow based on what data has been retrieved so far - it's not the approach I should follow. Or is there a way, what do you think?
well thats more 'business logic' - you can use this to help determine whats next, but its not something that this structure should handle on its own, for example your view controller/view model/etc could do something like:
func nextStep() -> Step {
if (try? partial.value(for: \.firstName)) == nil { return .firstNameStep }
if (try? partial.value(for: \.lastName)) == nil { return .lastNameStep }
return .complete
}
Probably a good candidate for adding a contains(_:)
to Partial<T>
👍
Comments for: http://iankeen.tech/2018/06/05/type-safe-temporary-models/