Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Cannot able create a Record from another Record (With all optional keys)

$
0
0

Alternatively, since there aren’t that many fields here, all of the pattern matching could be done at once.

let mapper: (a) => b = (a) => 
  switch a {
    | {t, l, p} => {t, l: "int", p: "array"}
    | {t, l} => {t, l: "int"}
    | {t, p} => {t, p: "array"}
    | {l, p} => {l: "int", p: "array"}
    | {t} => {t: t}
    | {l} => {l: "int"}
    | {p} => {p: "array"}
    | {} => {}
  }

Not that I’d recommend this for larger records.


Viewing all articles
Browse latest Browse all 2592

Trending Articles