Skip to content

Commit 726840a

Browse files
committed
Improve description of A.range and A.rangeBy
1 parent fbe23f6 commit 726840a

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

docs/api/generated/_array.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ function prependToAll<A>(delimiter: A): (xs: Array<A>) => Array<A>
612612

613613
### range
614614

615-
Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive).
615+
Returns a new inclusive array of numbers from `start` to `finish` (it returns an empty array when `start` > `finish`).
616616

617617

618618
```ts
@@ -622,7 +622,7 @@ function range(start: number, finish: number): Array<number>
622622

623623
### rangeBy
624624

625-
Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive).
625+
Returns a new inclusive array of numbers from `start` to `finish` (it returns an empty array when `step` is 0 or negative, it also returns an empty array when `start` > `finish`).
626626

627627

628628
```ts

src/Array/Array.res

+10-4
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ let prependToAll = (xs, delimiter) =>
5555

5656
%comment("Creates a new array with the separator interposed between elements.")
5757
@gentype
58-
let intersperse = (xs, delimiter) =>
58+
let intersperse = (xs, delimiter) => {
5959
Belt.Array.reduceWithIndexU(xs, [], (. acc, value, index) => {
6060
switch index {
6161
| x if xs->length->pred == x => Js.Array2.push(acc, value)
6262
| _ => Js.Array2.pushMany(acc, [value, delimiter])
6363
}->ignore
6464
acc
6565
})
66+
}
6667

6768
%comment("Returns `Some(value)` at the given index, or `None` if the given index is out of range.")
6869
@gentype
@@ -380,11 +381,15 @@ let sliceToEnd = (xs, offset) => Belt.Array.sliceToEnd(xs, offset)
380381
@gentype
381382
let eq = (xs0, xs1, comparatorFn) => Belt.Array.eqU(xs0, xs1, comparatorFn)
382383

383-
%comment("Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive).")
384+
%comment(
385+
"Returns a new inclusive array of numbers from `start` to `finish` (it returns an empty array when `start` > `finish`)."
386+
)
384387
@gentype
385388
let range = (start, finish) => Belt.Array.range(start, finish)
386389

387-
%comment("Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive).")
390+
%comment(
391+
"Returns a new inclusive array of numbers from `start` to `finish` (it returns an empty array when `step` is 0 or negative, it also returns an empty array when `start` > `finish`)."
392+
)
388393
@gentype
389394
let rangeBy = (start, finish, step) => Belt.Array.rangeBy(start, finish, ~step)
390395

@@ -623,11 +628,12 @@ let removeFirst = (xs, value) => removeFirstBy(xs, value, (x, y) => x == y)
623628

624629
%comment("Creates a new array of each value paired with its index in a tuple.")
625630
@gentype
626-
let zipWithIndex = xs =>
631+
let zipWithIndex = xs => {
627632
Belt.Array.reduceWithIndexU(xs, [], (. acc, value, index) => {
628633
Js.Array2.push(acc, (value, index))->ignore
629634
acc
630635
})
636+
}
631637

632638
%comment(
633639
"Returns `true` if all elements of the array match the predicate function, otherwise, returns `false`."

src/Array/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,13 @@ export declare function eq<A>(
482482
comparatorFn: (_1: A, _2: A) => boolean,
483483
): (xs0: Array<A>) => boolean
484484

485-
/** Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive). */
485+
/** Returns a new inclusive array of numbers from `start` to `finish` (it returns an empty array when `start` > `finish`). */
486486

487487
export declare function range(finish: number): (start: number) => Array<number>
488488

489489
export declare function range(start: number, finish: number): Array<number>
490490

491-
/** Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive). */
491+
/** Returns a new inclusive array of numbers from `start` to `finish` (it returns an empty array when `step` is 0 or negative, it also returns an empty array when `start` > `finish`). */
492492

493493
export declare function rangeBy(
494494
finish: number,

0 commit comments

Comments
 (0)