I have a record type:
type Person =
{
Name : string
Age : int
}
And I need a function which returns new instances of this record with default (in C# point of view) fields.
I can do it like this:
let f =
{
Name = ""
Age = 0
}
but I would like to avoid all fields enumeration and use something like this:
let f = new Person
Is there any way to do it ?
Get the default values for fields for a new record of a specified object and optional record type. After getting the default values, make a request to POST /ui-api/records to create the record.
What Does Default Values - Database Mean? Default values, in the context of databases, are preset values defined for a column type. Default values are used when many records hold similar data.
Default field values automatically insert the value of a custom field when a new record is created. You can use a default value on a formula for some types of fields or exact values, such as Checked or Unchecked for checkbox fields. After you have defined default values: The user chooses to create a new record.
F# allows adding methods/properties to records and discriminated unions:
type Person =
{
Name: string
Age: int
}
with
static member Default = { Name = ""; Age = 0 }
In FSI:
> Person.Default;;
val it : Person = {Name = "";
Age = 0;}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With