Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Aug 8, 2024
1 parent 63621ab commit f24bad6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
10 changes: 8 additions & 2 deletions chain.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* Chains multiple iterables together.
*
* @param iterables - The iterables to chain.
* @param ...iterables - The iterables to chain.
* @returns The chained iterable.
* @see {@link module:iterutil/async/chain.chain} for the asynchronous version.
*
* @example
* ```ts
Expand All @@ -20,6 +19,10 @@
* const iter = chain([1, 2], ["a", "b"], [true]);
* console.log([...iter]); // [1, 2, "a", "b", true]
* ```
*
* ## See also
*
* - {@link module:iterutil/async/chain.chain} for the asynchronous version.
*/
export function* chain<T extends Iterable<unknown>[]>(
...iterables: T
Expand All @@ -29,6 +32,9 @@ export function* chain<T extends Iterable<unknown>[]>(
}
}

/**
* @internal
*/
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
5 changes: 4 additions & 1 deletion chunked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @param iterable - The iterable to chunk.
* @param size - The size of each chunk.
* @return The chunked iterable.
* @see {@link module:iterutil/async/chunked.chunked} for the asynchronous version.
*
* @example
* ```ts
Expand All @@ -13,6 +12,10 @@
* const iter = chunked([1, 2, 3, 4, 5], 2);
* console.log([...iter]); // [[1, 2], [3, 4], [5]]
* ```
*
* ## See also
*
* - {@link module:iterutil/async/chunked.chunked} for the asynchronous version.
*/
export function* chunked<T>(
iterable: Iterable<T>,
Expand Down
10 changes: 6 additions & 4 deletions compact.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/**
* Removes all nullish ({@codelink null} or {@codelink undefined}) values from an iterable.
* Removes all nullish ({@linkcode null} or {@linkcode undefined}) values from an iterable.
*
* @param iterable - The iterable to compact.
* @returns The compacted iterable.
* @see {@link module:iterutil/async/compact.compact} for the asynchronous version.
* @see {@link module:iterutil/compress.compress} to select elements based on a selector iterable.
* @see {@link module:iterutil/filter.filter} to remove values based on a predicate.
*
* @example
* ```ts
Expand All @@ -14,6 +11,11 @@
* const iter = compact([1, undefined, 2, null, 3]);
* console.log([...iter]); // [1, 2, 3]
* ```
*
* ## See also
* - {@link module:iterutil/async/compact.compact} for the asynchronous version.
* - {@link module:iterutil/compress.compress} to select elements based on a selector iterable.
* - {@link module:iterutil/filter.filter} to remove values based on a predicate.
*/
export function* compact<T>(iterable: Iterable<T>): Iterable<NonNullable<T>> {
for (const value of iterable) {
Expand Down
8 changes: 5 additions & 3 deletions compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* @param iterable - The iterable to compress.
* @param selectors - The selectors to use.
* @returns The compressed iterable.
* @see {@link module:iterutil/async/compress.compress} for the asynchronous version.
* @see {@link module:iterutil/compact.compact} to remove nullish values from an iterable.
* @see {@link module:iterutil/filter.filter} to remove values based on a predicate.
*
* @example
* ```ts
Expand All @@ -15,6 +12,11 @@
* const iter = compress([1, 2, 3, 4, 5], [true, false, true, false, true]);
* console.log([...iter]); // [1, 3, 5]
* ```
*
* ## See also
* - {@link module:iterutil/async/compress.compress} for the asynchronous version.
* - {@link module:iterutil/compact.compact} to remove nullish values from an iterable.
* - {@link module:iterutil/filter.filter} to remove values based on a predicate.
*/
export function* compress<T>(
iterable: Iterable<T>,
Expand Down

0 comments on commit f24bad6

Please sign in to comment.