iterable-operator
Advanced tools
Comparing version 0.2.3 to 0.3.0
@@ -21,6 +21,7 @@ export declare class IterableOperator<T> implements Iterable<T> { | ||
filter(fn: (element: T, index: number) => boolean): IterableOperator<T>; | ||
flatten(): IterableOperator<T>; | ||
flatten<U>(): IterableOperator<U>; | ||
flatten(depth: number): IterableOperator<T>; | ||
flatten<U>(depth: number): IterableOperator<U>; | ||
flatten<U = T>(): IterableOperator<U>; | ||
flatten<U = T>(exclude: (value: Iterable<unknown>) => boolean): IterableOperator<U>; | ||
flattenDeep<U = T>(): IterableOperator<U>; | ||
flattenDeep<U = T>(depth: number): IterableOperator<U>; | ||
flattenDeep<U = T>(depth: number, exclude: (value: Iterable<unknown>) => boolean): IterableOperator<U>; | ||
head(): Iterable<T>; | ||
@@ -27,0 +28,0 @@ head(count: number): Iterable<T>; |
@@ -34,2 +34,5 @@ "use strict"; | ||
} | ||
flattenDeep(...args) { | ||
return new IterableOperator(pipe_1.flattenDeep(this.subject, ...args)); | ||
} | ||
head(...args) { | ||
@@ -36,0 +39,0 @@ return new IterableOperator(pipe_1.head(this.subject, ...args)); |
@@ -1,6 +0,2 @@ | ||
declare type NestedIterable<T> = Iterable<NestedIterable<T> | T>; | ||
export declare function flatten<T>(iterable: NestedIterable<T>): Iterable<T>; | ||
export declare function flatten<T>(iterable: NestedIterable<T>, depth: number): Iterable<T>; | ||
export declare function flatten<T, U>(iterable: NestedIterable<T>): Iterable<U>; | ||
export declare function flatten<T, U>(iterable: NestedIterable<T>, depth: number): Iterable<U>; | ||
export {}; | ||
export declare function flatten<T, U = T>(iterable: NestedIterable<T>): Iterable<U>; | ||
export declare function flatten<T, U = T>(iterable: NestedIterable<T>, exclude: (value: Iterable<unknown>) => boolean): Iterable<U>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function isChar(obj) { | ||
return typeof obj === 'string' && obj.length === 1; | ||
const flatten_deep_1 = require("./flatten-deep"); | ||
function flatten(iterable, exclude = () => false) { | ||
return flatten_deep_1.flattenDeep(iterable, 1, exclude); | ||
} | ||
function isIterable(obj) { | ||
return typeof obj[Symbol.iterator] === 'function'; | ||
} | ||
function flatten(iterable, depth = Infinity) { | ||
if (depth < 0) | ||
throw new RangeError('Invalid depth value'); | ||
return (function* () { | ||
for (const element of iterable) { | ||
if (depth > 0 && isIterable(element) && !isChar(element)) { | ||
yield* flatten(element, depth - 1); | ||
} | ||
else { | ||
yield element; | ||
} | ||
} | ||
})(); | ||
} | ||
exports.flatten = flatten; | ||
//# sourceMappingURL=flatten.js.map |
@@ -7,2 +7,3 @@ export * from './chunk-by'; | ||
export * from './flatten'; | ||
export * from './flatten-deep'; | ||
export * from './head'; | ||
@@ -9,0 +10,0 @@ export * from './map'; |
@@ -12,2 +12,3 @@ "use strict"; | ||
__export(require("./flatten")); | ||
__export(require("./flatten-deep")); | ||
__export(require("./head")); | ||
@@ -14,0 +15,0 @@ __export(require("./map")); |
{ | ||
"name": "iterable-operator", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "Minimalist utility for JavaScript Iterable.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46773
98
694