Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type safe temporary models #7

Open
IanKeen opened this Issue Jun 5, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@IanKeen
Copy link
Owner

IanKeen commented Jun 5, 2018

@zapko

This comment has been minimized.

Copy link

zapko commented Jun 21, 2018

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?

@IanKeen

This comment has been minimized.

Copy link
Owner Author

IanKeen commented Jun 28, 2018

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.

@zapko

This comment has been minimized.

Copy link

zapko commented Jun 28, 2018

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?

@IanKeen

This comment has been minimized.

Copy link
Owner Author

IanKeen commented Jun 28, 2018

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> 👍

@IanKeen IanKeen added the comments label Mar 1, 2019

@IanKeen IanKeen self-assigned this Mar 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.