ParseModule
PackageReified.Parse
Primitive parsers for untrusted serialized input.
Summary
| Name | Signature | Synopsis |
|---|---|---|
| int | int text | Parses a 32-bit integer. |
| long | long text | Parses a 64-bit integer. |
| decimal | decimal text | Parses a decimal number. |
| float | float text | Parses a double-precision floating point number. |
| bool | bool text | Parses a boolean. |
| guid | guid text | Parses a GUID. |
| dateTime | dateTime text | Parses a date and time value. |
| dateTimeOffset | dateTimeOffset text | Parses a date and time value with offset. |
| dateOnly | dateOnly text | Parses a date-only value. |
| timeOnly | timeOnly text | Parses a time-only value. |
| enum | enum text | Parses an enum value by name or numeric text. |
| optional | optional parser input | Parses an optional input, preserving a present input's parsing failure. |
| optionalOr | optionalOr fallback parser input | Parses an optional input, using the supplied fallback only when the input is absent. |
| intOption | intOption text | Parses an optional integer. |
| boolOption | boolOption text | Parses an optional Boolean. |
| decimalOption | decimalOption text | Parses an optional decimal. |
| guidOption | guidOption text | Parses an optional GUID. |
| intOrDefault | intOrDefault fallback text | Parses an optional integer, using the supplied fallback only when the input is absent. |
| boolOrDefault | boolOrDefault fallback text | Parses an optional Boolean, using the supplied fallback only when the input is absent. |
| decimalOrDefault | decimalOrDefault fallback text | Parses an optional decimal, using the supplied fallback only when the input is absent. |
Parses a 32-bit integer.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Returns
Result<int, ParseError>
Parses a 64-bit integer.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Returns
Result<int64, ParseError>
Parses a decimal number.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Returns
Result<decimal, ParseError>
Parses a double-precision floating point number.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Returns
Result<float, ParseError>
Parses a boolean.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Returns
Result<bool, ParseError>
Parses a GUID.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Returns
Result<Guid, ParseError>
Parses a date and time value.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Returns
Result<DateTime, ParseError>
Parses a date and time value with offset.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Returns
Result<DateTimeOffset, ParseError>
Parses a date-only value.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Returns
Result<DateOnly, ParseError>
Parses a time-only value.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Returns
Result<TimeOnly, ParseError>
Parses an enum value by name or numeric text.
Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Returns
Result<'enum, ParseError>
Parses an optional input, preserving a present input's parsing failure.
Parameters
| Name | Type | Description |
|---|---|---|
| parser | 'raw -> Result<'value, 'error> | |
| input | 'raw option |
Returns
Result<'value option, 'error>
Verification Examples
Parse.optional Parse.int None = Ok None
Parse.optional Parse.int (Some "42") = Ok (Some 42)
Parse.optional Parse.int (Some "bad") = Error (ParseError.InvalidFormat ("int", "bad"))Parses an optional input, using the supplied fallback only when the input is absent.
Parameters
| Name | Type | Description |
|---|---|---|
| fallback | 'value | |
| parser | 'raw -> Result<'value, 'error> | |
| input | 'raw option |
Returns
Result<'value, 'error>
Verification Examples
Parse.optionalOr 80 Parse.int None = Ok 80
Parse.optionalOr 80 Parse.int (Some "443") = Ok 443
Parse.optionalOr 80 Parse.int (Some "bad") = Error (ParseError.InvalidFormat ("int", "bad"))Parses an optional integer. Absence returns
Ok None; malformed present text returns its parsing error.Parameters
| Name | Type | Description |
|---|---|---|
| text | string option |
Returns
Result<int option, ParseError>
Verification Examples
Parse.intOption (Some "42") = Ok (Some 42)Parses an optional Boolean. Absence returns
Ok None; malformed present text returns its parsing error.Parameters
| Name | Type | Description |
|---|---|---|
| text | string option |
Returns
Result<bool option, ParseError>
Verification Examples
Parse.boolOption (Some "true") = Ok (Some true)Parses an optional decimal. Absence returns
Ok None; malformed present text returns its parsing error.Parameters
| Name | Type | Description |
|---|---|---|
| text | string option |
Returns
Result<decimal option, ParseError>
Verification Examples
Parse.decimalOption (Some "12.5") = Ok (Some 12.5M)Parses an optional GUID. Absence returns
Ok None; malformed present text returns its parsing error.Parameters
| Name | Type | Description |
|---|---|---|
| text | string option |
Returns
Result<Guid option, ParseError>
Verification Examples
Parse.guidOption None = Ok NoneParses an optional integer, using the supplied fallback only when the input is absent.
Parameters
| Name | Type | Description |
|---|---|---|
| fallback | int | |
| text | string option |
Returns
Result<int, ParseError>
Verification Examples
Parse.intOrDefault 80 None = Ok 80Parses an optional Boolean, using the supplied fallback only when the input is absent.
Parameters
| Name | Type | Description |
|---|---|---|
| fallback | bool | |
| text | string option |
Returns
Result<bool, ParseError>
Verification Examples
Parse.boolOrDefault false None = Ok false