mirror of
https://github.com/hanzoai/numscript.git
synced 2026-10-30 18:26:57 +00:00
Modules declare go 1.27.1 and the build images follow. go fix applied the modernizers, and the interpreter's parseArg, evaluateExprAs and evaluateOptExprAs are now generic methods on the parser and program state they take. omitzero is not applied, since it changes what the JSON says. Co-Authored-By: Claude Opus 5 <[email protected]>
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package interpreter
|
|
|
|
import (
|
|
"maps"
|
|
|
|
"github.com/formancehq/numscript/internal/utils"
|
|
)
|
|
|
|
func (m AccountsMetadata) fetchAccountMetadata(account string) AccountMetadata {
|
|
return utils.MapGetOrPutDefault(m, account, func() AccountMetadata {
|
|
return AccountMetadata{}
|
|
})
|
|
}
|
|
|
|
func (m AccountsMetadata) DeepClone() AccountsMetadata {
|
|
cloned := make(AccountsMetadata)
|
|
for account, accountBalances := range m {
|
|
for asset, metadataValue := range accountBalances {
|
|
clonedAccountBalances := cloned.fetchAccountMetadata(account)
|
|
utils.MapGetOrPutDefault(clonedAccountBalances, asset, func() string {
|
|
return metadataValue
|
|
})
|
|
}
|
|
}
|
|
return cloned
|
|
}
|
|
|
|
func (m AccountsMetadata) Merge(update AccountsMetadata) {
|
|
for acc, accBalances := range update {
|
|
cachedAcc := utils.MapGetOrPutDefault(m, acc, func() AccountMetadata {
|
|
return AccountMetadata{}
|
|
})
|
|
|
|
maps.Copy(cachedAcc, accBalances)
|
|
}
|
|
}
|
|
|
|
func (m AccountsMetadata) PrettyPrint() string {
|
|
header := []string{"Account", "Name", "Value"}
|
|
|
|
var rows [][]string
|
|
for account, accMetadata := range m {
|
|
for name, value := range accMetadata {
|
|
row := []string{account, name, value}
|
|
rows = append(rows, row)
|
|
}
|
|
}
|
|
|
|
return utils.CsvPretty(header, rows, true)
|
|
}
|