F #: how to use the "with" constructor for more values

In F #, I can do:

let card = { anotherCard with Cost = 4 } 

But I want:

 let card = { anotherCard with Cost = 4 with WinPoints = 5 } 

or at least have one liner, right now I have to:

 let cardTemp = { anotherCard with Cost = 4 } let card = { cardTemp with WinPoints = 5 } 
+5
source share
1 answer

You can separate multiple field setters with a semicolon:

 let card = { anotherCard with Cost = 4; WinPoints = 5 } 

You can also put fields on separate lines (without comma separators):

 let card = { anotherCard with Cost = 4 WinPoints = 5 } 
+15
source

Source: https://habr.com/ru/post/1271547/


All Articles