Skip to content

Update immutable object #14

Description

@ifle

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");

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions