DeepCopy icon indicating copy to clipboard operation
DeepCopy copied to clipboard

Update immutable object

Open ifle opened this issue 8 years ago • 2 comments

What I really want is something like F# records. Those a helpful feature called Copy and Update Expressions:

type Person = {
    FirstName: string
    LastName: string
    Email: string
}

let person = { FirstName = "first"; LastName = "last"; Email = "email" }
let updatedEmail = { person with Email = "newEmail" } // Copy and Update Expression

Will be nice to create extension method based on deepcopier that will copy and override values like this:

class Person
{
      public string FirstName { get; }
      public string LastName { get; }

     public Person(string firstName, string lastName)
    {
          FirstName = firstName;
          LastName = lastName;
    }
}

var person = new Person("bob", "jonhs");
var person2 = person.Update({ FirstName = "michael" });
var person3 = person.Update(p => p.FirstName, "michael");

ifle avatar Nov 20 '17 07:11 ifle

That sounds like a pretty cool idea, but it's a bit too out-of-scope for this project. It would be worth forking

ReubenBond avatar Nov 20 '17 07:11 ReubenBond

It would be nice if something like this did exist. Possibly we could have a second project within this repo which adds that kind of functionality.

ReubenBond avatar Dec 06 '17 01:12 ReubenBond