I’m currently trying out rescript and I was wondering if there is something like a .bind method or syntactic sugar to simplify nested switches where values depend on one another?
The new let? feature can help a lot with this. Your code using that feature instead:
let value = {
let? Some(id) = c->Context.req->HonoRequest.param("id")
let? Some(channel) = await Environment.db->Channel.Repo.select(id)
let sandbox = channel.sandboxId->Sandbox.findContainerById
let prompt = promptSchema->SuryStandardSchema.valid(c, "json")
await Sandbox.prompt(sandbox, prompt.message)
Some(c->Context.json({"message": "huuray"}))
}
value->Option.getOr(c->Context.text("not found", ~status=404))
Note that let value = { is in a block, because let? expects the you to return either option or result from the current block, and you want to remap it to that None default value you had.