Skip to content

Instantly share code, notes, and snippets.

@jdeisenberg
Created October 15, 2018 18:02
Show Gist options
  • Save jdeisenberg/361a555571b14717a65f21b40a4348d0 to your computer and use it in GitHub Desktop.
Save jdeisenberg/361a555571b14717a65f21b40a4348d0 to your computer and use it in GitHub Desktop.
type marshalled_location = {.
"administrative_area_level_1": string,
"country": string,
"locality": string,
"postal_code": string,
"route": string,
"street_number": string };
let quote = (s:string): string => {
"\"" ++ s ++ "\"";
};
let field = (fieldName, fieldValue) => {
quote(fieldName) ++ ":" ++ quote(fieldValue);
};
let locationToString = (m: marshalled_location) => {
"{" ++ Js.Array.joinWith(",",
[| field("administrative_area_level_1", m##administrative_area_level_1),
field("country", m##country),
field("locality", m##locality),
field("postal_code", m##postal_code),
field("route", m##route),
field("street_number", m##street_number) |]) ++ "}"
};
type input = {
key: string,
id: string,
placeholder: string,
input_type: string,
location: option(marshalled_location)
};
let toString = (inp: input) : string =>
{
"[" ++ Js.Array.joinWith(",",
[|quote(inp.key), quote(inp.id), quote(inp.placeholder), quote(inp.input_type)|]) ++
switch (inp.location) {
| Some(loc) => "," ++ locationToString(loc)
| None => ""
} ++ "]";
};
let loc1: marshalled_location = [%bs.obj {
administrative_area_level_1: "AZ",
country: "United States",
locality: "Tucson",
postal_code: "85710",
route: "East Broadway Boulevard",
street_number: "6339"}
];
let inp1 = {key: "0", id: "pickup address", placeholder: "address 0", input_type: "pickup",
location: Some(loc1)};
Js.log(toString(inp1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment