Skip to content

Commit

Permalink
Improve description of A.range and A.rangeBy
Browse files Browse the repository at this point in the history
  • Loading branch information
mobily committed Aug 26, 2022
1 parent fbe23f6 commit 726840a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/api/generated/_array.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ function prependToAll<A>(delimiter: A): (xs: Array<A>) => Array<A>

### range

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


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

### rangeBy

Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive).
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`).


```ts
Expand Down
14 changes: 10 additions & 4 deletions src/Array/Array.res
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ let prependToAll = (xs, delimiter) =>

%comment("Creates a new array with the separator interposed between elements.")
@gentype
let intersperse = (xs, delimiter) =>
let intersperse = (xs, delimiter) => {
Belt.Array.reduceWithIndexU(xs, [], (. acc, value, index) => {
switch index {
| x if xs->length->pred == x => Js.Array2.push(acc, value)
| _ => Js.Array2.pushMany(acc, [value, delimiter])
}->ignore
acc
})
}

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

%comment("Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive).")
%comment(
"Returns a new inclusive array of numbers from `start` to `finish` (it returns an empty array when `start` > `finish`)."
)
@gentype
let range = (start, finish) => Belt.Array.range(start, finish)

%comment("Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive).")
%comment(
"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`)."
)
@gentype
let rangeBy = (start, finish, step) => Belt.Array.rangeBy(start, finish, ~step)

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

%comment("Creates a new array of each value paired with its index in a tuple.")
@gentype
let zipWithIndex = xs =>
let zipWithIndex = xs => {
Belt.Array.reduceWithIndexU(xs, [], (. acc, value, index) => {
Js.Array2.push(acc, (value, index))->ignore
acc
})
}

%comment(
"Returns `true` if all elements of the array match the predicate function, otherwise, returns `false`."
Expand Down
4 changes: 2 additions & 2 deletions src/Array/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,13 @@ export declare function eq<A>(
comparatorFn: (_1: A, _2: A) => boolean,
): (xs0: Array<A>) => boolean

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

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

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

/** Returns a new array of numbers from `start` (inclusive) to `finish` (exclusive). */
/** 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`). */

export declare function rangeBy(
finish: number,
Expand Down

0 comments on commit 726840a

Please sign in to comment.