Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In F# I can do:

let card = { anotherCard with Cost = 4 }

But I want to do:

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

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

let cardTemp = { anotherCard with Cost = 4 }
let card = { cardTemp with WinPoints = 5 }
like image 505
Krzysztof Morcinek Avatar asked Sep 05 '17 19:09

Krzysztof Morcinek


1 Answers

You can separate multiple field setters with semicolons:

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

You can also put the fields on separate lines (without semicolon delimiters):

let card = { anotherCard with
                Cost = 4
                WinPoints = 5 }
like image 87
Chad Gilbert Avatar answered Sep 28 '22 06:09

Chad Gilbert