I would create default records and reduce the array:
let defaultSettings = {
startDate: "2025-08-24",
untilDate: "2025-08-25",
defaultCurrency: Currency("EUR"),
rates: Map.make(),
}
let defaultLedger = {
settings: defaultSettings,
}
let make: array<ParserResult.t> => t = lines =>
lines->Array.reduce(defaultLedger, (ledger, parserResult) => {
let settings = switch parserResult {
| Setting(DefaultCurrency(defaultCurrency)) => {...ledger.settings, defaultCurrency}
// | others
| _ => ledger.settings
}
{...ledger, settings}
})
You might want to make some fields optional instead:
type settings = {
startDate?: string,
untilDate?: string,
defaultCurrency: currency,
rates: Map.t<currency, float>,
}
Of course this comes at the cost of worse DX but you get the compiler to check if the dates are not just dummy ones.