Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update documentations #6

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![codecov](https://codecov.io/github/jsr-core/iterutil/graph/badge.svg?token=pfbLRGU5AM)](https://codecov.io/github/jsr-core/iterutil)

Iterator / AsyncIterator utility pack for JavaScript and TypeScript. Each module
is designed to work independently, avoiding internal interdependencies as much
is designed to work independently, avoiding internal inter-dependencies as much
as possible.

## Usage
Expand All @@ -16,7 +16,7 @@ both synchronous and asynchronous iterables (`Iterable` and `AsyncIterable`).

### chain

Chains multiple iterables or async iterables together.
Chains multiple iterables together.

```ts
import { chain } from "@core/iterutil/chain";
Expand Down Expand Up @@ -54,7 +54,7 @@ console.log(await toArray(iter)); // [[1, 2], [3, 4], [5]]

### compact

Removes all nullish values from an iterable.
Removes all nullish (`null` or `undefined`) values from an iterable.

```ts
import { compact } from "@core/iterutil/compact";
Expand All @@ -73,7 +73,7 @@ console.log(await toArray(iter)); // [1, 2, 3]

### compress

Compress an iterable by selecting elements using a selector iterable.
Compresses an iterable by selecting elements using a selector iterable.

```ts
import { compress } from "@core/iterutil/compress";
Expand Down Expand Up @@ -164,7 +164,7 @@ console.log(await toArray(iter)); // [3, 4, 5]

### enumerate

Enumerate an iterable.
Enumerates an iterable.

```ts
import { enumerate } from "@core/iterutil/enumerate";
Expand Down Expand Up @@ -318,7 +318,7 @@ await forEach([1, 2, 3], console.log);

### iter

Convert an iterable to an iterator.
Converts an iterable to an iterator.

```ts
import { iter } from "@core/iterutil/iter";
Expand Down Expand Up @@ -431,7 +431,7 @@ console.log(odd); // [1, 3, 5]

### range

Generate a range of numbers.
Generates a range of numbers.

```ts
import { range } from "@core/iterutil/range";
Expand Down Expand Up @@ -492,7 +492,7 @@ console.log(await some([1, 3, 5], (value) => value % 2 === 0)); // false

### take

Take the first `limit` items from the iterable.
Takes the first `limit` items from the iterable.

```ts
import { take } from "@core/iterutil/take";
Expand All @@ -511,7 +511,7 @@ console.log(await toArray(iter)); // [1, 2]

### takeWhile

Take elements from the iterable while the predicate is true.
Takes elements from the iterable while the predicate is true.

```ts
import { takeWhile } from "@core/iterutil/take-while";
Expand Down
7 changes: 4 additions & 3 deletions async/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
* console.log(await toArray(iter)); // [1, 2, 3, 4]
* ```
*
* It supports chaining malformed iterables.
*
* @example
* @example With malformed iterables
* ```ts
* import { toArray } from "@core/iterutil/async/to-array";
* import { chain } from "@core/iterutil/async/chain";
Expand All @@ -36,6 +34,9 @@ export async function* chain<
}
}

/**
* @inner
*/
export type Chain<T> = T extends readonly [] ? never
: T extends readonly [Iterable<infer U>] ? U
: T extends readonly [AsyncIterable<infer U>] ? U
Expand Down
2 changes: 1 addition & 1 deletion async/compact.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Removes all nullish values from an iterable.
* Removes all nullish (`null` or `undefined`) values from an iterable.
*
* @param iterable The iterable to compact.
* @returns The compacted iterable.
Expand Down
2 changes: 1 addition & 1 deletion async/compress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Compress an iterable by selecting elements using a selector iterable.
* Compresses an iterable by selecting elements using a selector iterable.
*
* @param iterable The iterable to compress.
* @param selectors The selectors to use.
Expand Down
5 changes: 2 additions & 3 deletions async/drop.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
* Drops the first `limit` items from the iterable.
*
* It throws an error if `limit` is less than 0.
*
* @param iterable The iterable to drop items from.
* @param limit The number of items to drop.
* @param limit The number of items to drop. It must be 0 or positive safe integer.
* @returns The iterable with the first `limit` items dropped.
* @throws {DropLimitError} If `limit` is less than 0 or non safe integer.
*
* @example
* ```ts
Expand Down
2 changes: 1 addition & 1 deletion async/enumerate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Enumerate an iterable.
* Enumerates an iterable.
*
* @param iterable The iterable to enumerate.
* @param start The starting index.
Expand Down
3 changes: 1 addition & 2 deletions async/first.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Returns the first element of an iterable.
* If the iterable is empty, returns `undefined`.
* Returns the first element of an iterable. If the iterable is empty, returns `undefined`.
*
* @param iterable The iterable to get the first element from.
* @returns The first element of the iterable, or `undefined` if the iterable is empty.
Expand Down
1 change: 1 addition & 0 deletions async/for_each.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @example
* ```ts
* import { forEach } from "@core/iterutil/async/for-each";
*
* await forEach([1, 2, 3], console.log);
* // 1
* // 2
Expand Down
2 changes: 1 addition & 1 deletion async/iter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Convert an iterable to an iterator.
* Converts an iterable to an iterator.
*
* @param iterable The iterable to convert.
* @returns The iterator.
Expand Down
7 changes: 3 additions & 4 deletions async/take.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
* Take the first `limit` items from the iterable.
*
* It throws an error if `limit` is less than 0.
* Takes the first `limit` items from the iterable.
*
* @param iterable The iterable to take items from.
* @param limit The number of items to take.
* @param limit The number of items to take. It must be 0 or positive safe integer.
* @returns The iterable with the first `limit` items taken.
* @throws {TakeLimitError} If `limit` is less than 0 or non safe integer.
*
* @example
* ```ts
Expand Down
2 changes: 1 addition & 1 deletion async/take_while.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Take elements from the iterable while the predicate is true.
* Takes elements from the iterable while the predicate is true.
*
* @param iterable The iterable to take elements from.
* @param fn The predicate to take elements with.
Expand Down
2 changes: 1 addition & 1 deletion async/uniq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* console.log(await toArray(iter)); // [1, 2, 3]
* ```
*
* @example
* @example With identify function
* ```ts
* import { toArray } from "@core/iterutil/async/to-array";
* import { uniq } from "@core/iterutil/async/uniq";
Expand Down
3 changes: 3 additions & 0 deletions async/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export async function* zip<
}
}

/**
* @inner
*/
export type Zip<T extends (Iterable<unknown> | AsyncIterable<unknown>)[]> = {
[P in keyof T]: T[P] extends Iterable<infer U> ? U
: T[P] extends AsyncIterable<infer U> ? U
Expand Down
7 changes: 4 additions & 3 deletions chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
* console.log([...iter]); // [1, 2, 3, 4]
* ```
*
* It supports chaining malformed iterables.
*
* @example
* @example With malformed iterables
* ```ts
* import { chain } from "@core/iterutil/chain";
*
Expand All @@ -30,6 +28,9 @@ export function* chain<T extends Iterable<unknown>[]>(
}
}

/**
* @inner
*/
export type Chain<T> = T extends readonly [] ? never
: T extends readonly [Iterable<infer U>] ? U
: T extends readonly [Iterable<infer U>, ...infer R] ? U | Chain<R>
Expand Down
2 changes: 1 addition & 1 deletion compact.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Removes all nullish values from an iterable.
* Removes all nullish (`null` or `undefined`) values from an iterable.
*
* @param iterable The iterable to compact.
* @returns The compacted iterable.
Expand Down
2 changes: 1 addition & 1 deletion compress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Compress an iterable by selecting elements using a selector iterable.
* Compresses an iterable by selecting elements using a selector iterable.
*
* @param iterable The iterable to compress.
* @param selectors The selectors to use.
Expand Down
5 changes: 2 additions & 3 deletions drop.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
* Drops the first `limit` items from the iterable.
*
* It throws an error if `limit` is less than 0.
*
* @param iterable The iterable to drop items from.
* @param limit The number of items to drop.
* @param limit The number of items to drop. It must be 0 or positive safe integer.
* @returns The iterable with the first `limit` items dropped.
* @throws {DropLimitError} If `limit` is less than 0 or non safe integer.
*
* @example
* ```ts
Expand Down
2 changes: 1 addition & 1 deletion enumerate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Enumerate an iterable.
* Enumerates an iterable.
*
* @param iterable The iterable to enumerate.
* @param start The starting index.
Expand Down
3 changes: 1 addition & 2 deletions first.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Returns the first element of an iterable.
* If the iterable is empty, returns `undefined`.
* Returns the first element of an iterable. If the iterable is empty, returns `undefined`.
*
* @param iterable The iterable to get the first element from.
* @returns The first element of the iterable, or `undefined` if the iterable is empty.
Expand Down
1 change: 1 addition & 0 deletions for_each.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @example
* ```ts
* import { forEach } from "@core/iterutil/for-each";
*
* forEach([1, 2, 3], console.log);
* // 1
* // 2
Expand Down
2 changes: 1 addition & 1 deletion iter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Convert an iterable to an iterator.
* Converts an iterable to an iterator.
*
* @param iterable The iterable to convert.
* @returns The iterator.
Expand Down
1 change: 1 addition & 0 deletions range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* @param stop The end of the range.
* @returns The range of numbers.
*
* @example
* ```ts
* import { range } from "@core/iterutil/range";
Expand Down
7 changes: 3 additions & 4 deletions take.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
* Take the first `limit` items from the iterable.
*
* It throws an error if `limit` is less than 0.
* Takes the first `limit` items from the iterable.
*
* @param iterable The iterable to take items from.
* @param limit The number of items to take.
* @param limit The number of items to take. It must be 0 or positive safe integer.
* @returns The iterable with the first `limit` items taken.
* @throws {TakeLimitError} If `limit` is less than 0 or non safe integer.
*
* @example
* ```ts
Expand Down
2 changes: 1 addition & 1 deletion take_while.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Take elements from the iterable while the predicate is true.
* Takes elements from the iterable while the predicate is true.
*
* @param iterable The iterable to take elements from.
* @param fn The predicate to take elements with.
Expand Down
2 changes: 2 additions & 0 deletions to_array.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Converts an iterable to an array.
*
* Note that users should use `Array.from` directly. This function exists for consistency with `async/to-array.toArray`.
*
* @param iterable The iterable to convert.
* @returns The array.
*
Expand Down
2 changes: 1 addition & 1 deletion uniq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* console.log([...iter]); // [1, 2, 3]
* ```
*
* @example
* @example With identify function
* ```ts
* import { uniq } from "@core/iterutil/uniq";
*
Expand Down
3 changes: 3 additions & 0 deletions zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export function* zip<U extends Iterable<unknown>[]>(
}
}

/**
* @inner
*/
export type Zip<T extends Iterable<unknown>[]> = {
[P in keyof T]: T[P] extends Iterable<infer U> ? U : never;
};