Created
December 18, 2017 12:37
-
-
Save gladimdim/a7a2284e210ed6110ba977b34c724fd5 to your computer and use it in GitHub Desktop.
FInal version of converting function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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