Proposing new syntax for zero-cost unwrapping options/results

let? works great to simplity functions that were already written to output option types:

let time = i => {
  let? Some(hour) = float(i)
  let? Some(minute) = float(i)
  let? Some(second) = float(i)
  let? Some(ms) = float(i)

  Some(hour * 60.0 * 60.0 + minute * 60.0 + second + ms / 1000.0)
}

also perfect for useEffect-like change track handlers who also return optional cleanup functions:

  Signal.useSignalEffect(_ => {
    let? Some(track) = Store.trackContainer.value->Dict.get(captionId->Types.asKey)
    track.mode = checked.value ? Showing : Hidden
    Some(_ => track.mode = Disabled) // clean-up
  })

An improvement over switch hadouken constructions, but they’re a bit clunky if surrounding function doesn’t return optional:

intervalRef.current = WebAPI.Window.setInterval2(
            window,
            ~handler=_ =>
              {
                let? Some(scroll) = scrollDiv.current
                scroll->WebAPI.HTMLDivElement.scrollBy2(~x=step, ~y=0.0)
                resetArrows(scroll)
                None
              }->ignore,
            ~timeout=100,
          )

Even if superfluous None and ->ignore are removed from compiled JS code it’s still a noise.

I was wondering if it was possible to write it like this instead:

                if scrollDiv.current is Some(scroll) {
                scroll->WebAPI.HTMLDivElement.scrollBy2(~x=step, ~y=0.0)
                resetArrows(scroll)
                }

where is is an operator doing type matching and returning a boolean. Sure, the weird part is that now a random operator can change lexical scope of everything that comes after it, introducing its own type matched constants.

This should also work for Null.t and Nullable.t.

Yeah, not having to write Null.toOption would be nice

That reminds me of Elixir with/when do expressions

with scroll when ref.current->Option.isSome