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

Copy and Update Record Lambdas #723

TheJayMann opened this Issue Feb 28, 2019 · 1 comment


None yet
3 participants
Copy link

TheJayMann commented Feb 28, 2019

Copy and Update Record Lambdas

I propose we add a new syntax to create a lambda function which copies and updates a record.

{ with Name; Age}

This would be syntactic sugar which would be translated as follows.

fun r name age -> { r with Name = name; Age = age }

Also, some record fields can be set directly.

{ with Name; Age; UpdatedAt = System.DateTime.UtcNow }
fun r name age -> { r with Name = name; Age = age; UpdatedAt = System.DateTime.UtcNow }

I've also considered the possibility of assigning the value of fields to that of other fields, though I'm unsure whether it would be better to assign the same value or the previous value, if it should be implemented at all.

{ with Name; Age; Nickname = Name }
// option 1, same value
fun r name age -> { r with Name = name; Age = age; Nickname = name }
// option 2, previous value
fun r name age -> { r with Name = name; Age = age; Nickname = r.Name }

Assuming that the record lambda needs to be qualified, the record name could be added to the expression.

{ Person with Name; Age }

Also, if necessary, the fun keyword could be used to ensure we are using a record lambda and not a record expression.

{ fun with Name; Age }

I have not considered the possibility of applying this to nested copy and update syntax, but I'm not against the idea if it can be implemented without too much complexity.

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S - M

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this

This comment has been minimized.

Copy link

dsyme commented Feb 28, 2019

I was wondering the other day about a whole swathe of similar improvements to the copy-and-update feature which would sort-of- align with this, and sort-of- conflict with it e.g.

           { state with Count.Increment();  } 


           { state with Count= state.Count.Increment() } 


           { state with Count |> increment } 


           { state with Count = state.Count |> increment }

(allowing both pipelined and OO notation)

I'm not saying we should do this, just was idly thinking about it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.