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

Trying to remove Caml_option in the generated JS

$
0
0

One thing you can do is to create your own Dict bindings that return nullable instead of Option.

module Dict = {
  type t<'a> = dict<'a>

  @get_index external get: (dict<'a>, string) => nullable<'a> = ""

  @val
  external fromArray: array<(string, 'a)> => dict<'a> = "Object.fromEntries"
}

let key = "a"
let observed = [(key, Set.make())]->Dict.fromArray
let sym = "x"

switch Dict.get(observed, key) {
| Value(eyes) =>
  if Set.delete(eyes, sym) {
    if Set.size(eyes) == 0 {
      ignore(%raw(`delete observed[key]`))
    }
  }

| _ => ()
}

Playground link


Viewing all articles
Browse latest Browse all 1794

Trending Articles