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

type a = {
  t ?: string,
  l ?: int,
  p ?: array<int>
}

type b = {
  t ?: string,
  l ?: string,
  p ?: string
}

let intToString : option<int> => option<string> = (s) => {
	switch s{
  	 | Some(r) => Some("int")
     | None => None 
  }
}
let arrayToString : option<array<int>> => option<string> = (s) => {
	switch s{
  	 | Some(r) => Some("array")
     | None => None 
  }
}

let mapper: (a) => b = (a) => {
  ({ t : ?a.t
  , l : ?a.l->intToString
  , p : ?a.p->arrayToString
  } : b)
}

let s = mapper({t : "Testing" })
Above line is giving this output { t : "Testing", l : undefined, p : undefined }
but I wanted to get this output { t : "Testing" }

How to write code for this in rescript ?


Viewing all articles
Browse latest Browse all 2592

Trending Articles