Context
In dhall-kubernetes you often have types such as List { mapKey : Text, mapValue : Text }
. For instance this is the type of the hard field in ResourceQuotaSpec
Objectif
Let’s say you want to provide a more safe interface using such a record:
{ Type =
{ `requests.cpu` : Text
, `requests.memory` : Text
, `limits.cpu` : Optional Text
, `limits.memory` : Text
}
, default =
{ `requests.cpu` = "1"
, `requests.memory` = "1Gi"
, `limits.cpu` = None Text
, `limits.memory` = "2Gi"
}
}
How would you go to convert this record to a map ?
Possible solution
Something like:
let toQuotaMap
: Quota → List { mapKey : Text, mapValue : Text }
= λ(config : Quota) →
let cpuLimit =
merge
{ None = [] : List { mapKey : Text, mapValue : Text }
, Some = λ(limit : Text) → toMap { `limits.cpu` = limit }
}
config.`limits.cpu`
in cpuLimit
# toMap
{ `requests.cpu` = config.`requests.cpu`
, `requests.memory` = config.`requests.memory`
, `limits.memory` = config.`limits.memory`
}
in
λ(config : Quota) →
{
hard = Some (toQuotaMap config)
}
Question
Is there a more idiomatic way to do this ?
Thanks