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

Convenience default implementations for mutable properties #615

Closed
sharplet opened this issue Mar 2, 2018 · 4 comments
Closed

Convenience default implementations for mutable properties #615

sharplet opened this issue Mar 2, 2018 · 4 comments

Comments

@sharplet
Copy link
Contributor

sharplet commented Mar 2, 2018

While experimenting with #613, I found that this little extension made it a lot easier to work with custom mutable property types:

extension MutablePropertyProtocol where Self: ComposableMutablePropertyProtocol {
    var value: Value {
        get { return withValue { $0 } }
        set { modify { $0 = newValue } }
    }

    func withValue<Result>(_ action: (Value) throws -> Result) rethrows -> Result {
        return try modify { try action($0) }
    }
}

Making your own custom mutable property is probably not a common use case, but nevertheless this seems like a useful extension, and could potentially remove some duplication in the codebase.

Thoughts?

@andersio
Copy link
Member

andersio commented Mar 2, 2018

The original plan was that ComposableMutablePropertyProtocol might replace MutablePropertyProtocol eventually, but the work hasn't been done/tried.

@mdiep
Copy link
Contributor

mdiep commented Mar 19, 2018

Those seem like reasonable default implementations. 👍

Why are you making custom mutable property types?

@sharplet
Copy link
Contributor Author

Why are you making custom mutable property types?

It cut down on some boilerplate while I've been experimenting with ideas for #613.

@RuiAAPeres
Copy link
Member

Hello. 👋 Thanks for opening this issue. Due to inactivity, we will soft close the issue. If you feel that it should remain open, please let us know. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants