rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Early return / break

Open cknitt opened this issue 2 weeks ago • 1 comments

Investigate implementing early return from functions / breaking from loops.

cknitt avatar Dec 04 '25 09:12 cknitt

I recently used this helper in my code:

let forOf: (array<'t>, 't => unit, unit => bool) => unit = %raw(`
function (items, callback, shouldBreak) {
  for (let i = 0; i < items.length; i++) {
    if (shouldBreak()) {
      break;
    }
    callback(items[i])
  }
}
`)

So, I would not mind early return from functions and breaking from loops.

nojaf avatar Dec 08 '25 08:12 nojaf