Skip to content

Instantly share code, notes, and snippets.

@gladimdim
Created December 18, 2017 12:27
Show Gist options
  • Save gladimdim/1a9813b8fe416c7a57be79617427c322 to your computer and use it in GitHub Desktop.
Save gladimdim/1a9813b8fe416c7a57be79617427c322 to your computer and use it in GitHub Desktop.
Reason Records
type metricCount = {type_: string};
type metricWithLabel = {
type_: string,
label: string
};
let createCountWithLabel = (label) : metricWithLabel => {type_: "COUNT", label};
type metric =
| MetricCount(metricCount)
| MetricWithLabel(metricWithLabel);
let transformToCount20 = (oldJson) : metric => {
let label = Json.Decode.(oldJson |> optional(field("label", string)));
switch label {
| Some(v) => MetricWithLabel(createCountWithLabel(v))
| None => MetricCount({type_: "COUNT"})
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment