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

feat: add With() method based on with keywork from F# #44

Closed
Odonno opened this issue Nov 22, 2017 · 7 comments
Closed

feat: add With() method based on with keywork from F# #44

Odonno opened this issue Nov 22, 2017 · 7 comments
Milestone

Comments

@Odonno
Copy link
Contributor

Odonno commented Nov 22, 2017

It would be interesting to add immutable syntax using the with keyword from F#. Here is a proposal :

var oldComputer = new Computer
{
    Os = "Windows 7",
    Cpu = "Intel Core i5"
};

var computerWithNewOs = oldComputer.With(new { Os = "Windows 10" });
var computerWithNewCpu = computerWithNewOs.With(new { Cpu = "Intel Core i7" });
@DavidArno
Copy link
Owner

Whilst this is in theory achievable, the only way I can think to do this would necessitate a lot of reflection use and so would be slow. I'd question whether it's worth it therefore when pattern-based with expressions are currently pencilled in for C# 8.

@Odonno
Copy link
Contributor Author

Odonno commented Nov 24, 2017

@DavidArno Indeed, it would use reflection to create a new Immutable object and detect properties to overwrite. I can start with a PR until we have C# 8.

@DavidArno
Copy link
Owner

PR's are always welcome 😀

@DavidArno
Copy link
Owner

Bit slow on the uptake here, but I have just realised that because this feature requires System.Runtime it breaks the netstandard 1.0 version of SuccincT. I could update that to netstandard 1.5, but that would be a breaking change.

I am therefore pulling this feature from the v3.1 release and will reschedule it for the v4.0 release (which is allowed to make such breaking changes).

Apologies for the last minute change of plan here.

@DavidArno DavidArno modified the milestones: V3.1.0, V4.0 Dec 5, 2017
DavidArno added a commit that referenced this issue Dec 5, 2017
Renamed to TryWith and TryCopy
With (version that throws exceptions rather than using an Option<T> type) added
Various code changes to support edge-case badly behaved types
@Odonno
Copy link
Contributor Author

Odonno commented Dec 5, 2017

Good to know. I will have some time to make some adjustments on the feature so.

@Odonno
Copy link
Contributor Author

Odonno commented May 16, 2018

@DavidArno For information, I have made the wiki page for Copy/With functions https://github.com/DavidArno/SuccincT/wiki/Copy---With

DavidArno added a commit that referenced this issue Jul 23, 2018
Still need to add tests for Copy.
DavidArno added a commit that referenced this issue Nov 26, 2018
(I think - it's been so many months since I've been near SuccincT, I may have missed something).
Took advantage of the Deconstruct on the Success<T> type and modified various tests to use this. Found a bug in the process (the paramter name on the deconstruct was wrong, so this is now fixed.
@DavidArno
Copy link
Owner

Released with v4.

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

No branches or pull requests

2 participants