@mark1russell7/collections 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/collections",
4
- "version": "0.7.1",
4
+ "version": "0.7.2",
5
5
  "description": "Collections with no dependencies: lists, maps, queues, a summary tree, channels, lazy operations and dependency graphs.",
6
6
  "keywords": [
7
7
  "collections",
package/src/fx/iter.ts CHANGED
@@ -7,9 +7,9 @@
7
7
  * @example
8
8
  * const result = pipe(
9
9
  * [1, 2, 3, 4, 5],
10
- * map(x => x * 2),
11
- * filter(x => x > 5),
12
- * take(2),
10
+ * (it) => map(it, x => x * 2),
11
+ * (it) => filter(it, x => x > 5),
12
+ * (it) => take(it, 2),
13
13
  * toArray
14
14
  * ) // [6, 8]
15
15
  */
@@ -76,13 +76,14 @@ export function* flatten<T>(iterable: Iterable<Iterable<T>>): Generator<T> {
76
76
  // ============================================================================
77
77
 
78
78
  /**
79
- * This function takes the first n elements.
79
+ * This function takes the first n elements. It reads no element after the n-th one, and it reads nothing when n is 0.
80
80
  */
81
81
  export function* take<T>(iterable: Iterable<T>, n: number): Generator<T> {
82
+ if (n <= 0) return;
82
83
  let count = 0;
83
84
  for (const value of iterable) {
84
- if (count++ >= n) break;
85
85
  yield value;
86
+ if (++count >= n) return;
86
87
  }
87
88
  }
88
89