Skip to content

Instantly share code, notes, and snippets.

@gladimdim
Created December 18, 2017 12:37
Show Gist options
  • Save gladimdim/a7a2284e210ed6110ba977b34c724fd5 to your computer and use it in GitHub Desktop.
Save gladimdim/a7a2284e210ed6110ba977b34c724fd5 to your computer and use it in GitHub Desktop.
FInal version of converting function
type metricCount = {type_: string};
type metricWithLabel = {
type_: string,
label: string
};
let createCountWithLabel = (label) : metricWithLabel => {type_: "COUNT", label};
let countMetric: metricCount = {type_: "COUNT"};
module MetricEncoder = {
let encodeCountMetricWithLabel = (m: metricWithLabel) =>
Json.Encode.(object_([("type", string(m.type_)), ("label", string(m.label))]));
let encodeCountMetric = (m: metricCount) => Json.Encode.(object_([("type", string(m.type_))]));
};
let transformToCount20 = (oldJson) => {
let label = Json.Decode.(oldJson |> optional(field("label", string)));
switch label {
| Some(v) => createCountWithLabel(v) |> MetricEncoder.encodeCountMetricWithLabel
| None => countMetric |> MetricEncoder.encodeCountMetric
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment