API / Belt / Range

You are currently looking at the < v8.2.0 docs (Reason v3.6 syntax edition). You can find the latest API docs here.

(These docs cover all versions between v3 to v8 and are equivalent to the old BuckleScript docs before the rebrand)

Range

A small utility module to provide inclusive range operations for [start, finish]. Internally it is relying on loops instead of creating new arrays, which makes it pretty performant and memory friendly.

forEachU

RE
let forEachU: (int, int, [@bs] (int => unit)) => unit;

forEach

RE
let forEach: (int, int, int => unit) => unit;

forEach(start, finish, action);

equivalent to Belt.Array.(forEach(range(start, finish), action));

RE
Belt.Range.forEach(0, 4, (i) => Js.log(i)); /** * prints: * 0 * 1 * 2 * 3 * 4 */

everyU

RE
let everyU: (int, int, [@bs] (int => bool)) => bool;

every

RE
let every: (int, int, int => bool) => bool;

every(start, finish, p);

equivalent to Belt.Array.(every(range(start, finish), p));

RE
Belt.Range.every(0, 4, (i) => i < 5); /* true */ Belt.Range.every(0, 4, (i) => i < 4); /* false */

everyByU

RE
let everyByU: (int, int, ~step: int, [@bs] (int => bool)) => bool;

everyBy

RE
let everyBy: (int, int, ~step: int, int => bool) => bool;

everyBy(start, finish, ~step, p);

See Belt_Array.rangeBy

equivalent to Belt.Array.(every(rangeBy(start, finish, ~step), p));

RE
Belt.Range.everyBy(0, 4, ~step=1, (i) => i mod 2 === 0); /* false */ Belt.Range.everyBy(0, 4, ~step=2, (i) => i mod 2 === 0); /* true */

someU

RE
let someU: (int, int, [@bs] (int => bool)) => bool;

some

RE
let some: (int, int, int => bool) => bool;

some(start, finish, p);

equivalent to Belt.Array.(some(range(start, finish), p));

RE
Belt.Range.some(0, 4, (i) => i > 5); /* false */ Belt.Range.some(0, 4, (i) => i > 2); /* true */

someByU

RE
let someByU: (int, int, ~step: int, [@bs] (int => bool)) => bool;

someBy

RE
let someBy: (int, int, ~step: int, int => bool) => bool;

someBy(start, finish, ~step, p);

See Belt_Array.rangeBy

equivalent to Belt.Array.(some(rangeBy(start, finish, ~step), p));

RE
Belt.Range.someBy(1, 5, ~step=2, (i) => i mod 2 === 0); /* false */ Belt.Range.someBy(0, 4, ~step=2, (i) => i mod 2 === 0); /* true */