Skip to content

Update immutable object #14

@ifle

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

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