Logo GenPRES

Csv Module

Reads a typed value from a named column of a row of text and splits CSV text into rows. An unknown column raises a KeyNotFoundException.

Types and nested modules

Type/Module Description

Tests

Holds the Unquote tests of the Csv cast, parse and column functions.

DataType

Functions and values

Function or value Description

getColumn dataType columns row name

Full Usage: getColumn dataType columns row name

Parameters:
    dataType : DataType
    columns : string array
    row : string array
    name : string

Returns: 'T
Modifiers: inline
Type parameters: 'T

Get a column from a row of a CSV file. Example: getColumn StringData [| "a"; "b" |] [| "1"; "2" |] "a" will return "1".

Header names are matched case-insensitively, and an unknown column name RAISES a KeyNotFoundException rather than yielding a default. Callers that parse a whole sheet wrap this in try/with and surface the failure as an Error, which makes the header row of a sheet a checkable contract: feed a parser exactly the column set it is supposed to read and it succeeds, drop any one of them and it fails. The GenFORM column-contract tests rely on that. A column that may legitimately be absent therefore needs an explicit tolerant wrapper at the call site (see DoseRuleData.getIfNull) - there is no way to express optionality here.

dataType : DataType
columns : string array
row : string array
name : string
Returns: 'T

getDecimalColumn columns sl s

Full Usage: getDecimalColumn columns sl s

Parameters:
    columns : string array
    sl : string array
    s : string

Returns: decimal
columns : string array
sl : string array
s : string
Returns: decimal

getDecimalOptionColumn columns sl s

Full Usage: getDecimalOptionColumn columns sl s

Parameters:
    columns : string array
    sl : string array
    s : string

Returns: decimal option
columns : string array
sl : string array
s : string
Returns: decimal option

getFloatColumn columns sl s

Full Usage: getFloatColumn columns sl s

Parameters:
    columns : string array
    sl : string array
    s : string

Returns: float
columns : string array
sl : string array
s : string
Returns: float

getFloatOptionColumn columns sl s

Full Usage: getFloatOptionColumn columns sl s

Parameters:
    columns : string array
    sl : string array
    s : string

Returns: float option
columns : string array
sl : string array
s : string
Returns: float option

getInt32Column columns sl s

Full Usage: getInt32Column columns sl s

Parameters:
    columns : string array
    sl : string array
    s : string

Returns: int
columns : string array
sl : string array
s : string
Returns: int

getInt32OptionColumn columns sl s

Full Usage: getInt32OptionColumn columns sl s

Parameters:
    columns : string array
    sl : string array
    s : string

Returns: int option
columns : string array
sl : string array
s : string
Returns: int option

getStringColumn columns sl s

Full Usage: getStringColumn columns sl s

Parameters:
    columns : string array
    sl : string array
    s : string

Returns: string
columns : string array
sl : string array
s : string
Returns: string

parse isOption typeDescr tryParse x

Full Usage: parse isOption typeDescr tryParse x

Parameters:
    isOption : bool
    typeDescr : 'a
    tryParse : 'b -> 'c option
    x : 'b

Returns: objnull
Modifiers: inline
Type parameters: 'a, 'b, 'c
 Flexible parsing function with optional option wrapping and error handling.

 This function attempts parsing using the provided tryParse function.
 Depending on the isOption flag, the parsed value can be wrapped in an Option or not.
 If parsing fails, it handles errors by returning None or throwing an exception.

 Parameters:
   - isOption: Flag indicating whether to wrap the parsed value in an Option.
   - typeDescr: Description of the target type for error messages.
   - tryParse: Function attempting to parse the input value and returning an Option.
   - x: Input value to be parsed.

 Returns:
   - Parsed value (wrapped in Option if isOption is true).

 Exceptions:
   - Throws an exception with error message if parsing fails and isOption is false.
isOption : bool
typeDescr : 'a
tryParse : 'b -> 'c option
x : 'b
Returns: objnull

parseCSV s

Full Usage: parseCSV s

Parameters:
    s : string

Returns: string array array
s : string
Returns: string array array

tryCast dt x

Full Usage: tryCast dt x

Parameters:
Returns: 'T
Modifiers: inline
Type parameters: 'T

Try to cast a string to a value of the given type. Example: "123" |> tryCast Int32Data will return 123.

dt : DataType
x : string
Returns: 'T

Type something to start searching.