Commit af09236 Shil Sinha
committed
1 parent 36eb702 commit af09236 Copy full SHA for af09236
File tree 1 file changed +21
-1
lines changed
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,18 @@ async function *filterIt(filter, iter) {
15
15
}
16
16
}
17
17
18
+ async function * limitIt ( limit , iter ) {
19
+ let count = 0 ;
20
+ for await ( const item of iter ) {
21
+ if ( count === limit ) {
22
+ break
23
+ }
24
+
25
+ count ++ ;
26
+ yield item ;
27
+ }
28
+ }
29
+
18
30
/**
19
31
* @template T
20
32
* @implements AsyncIterable<T>
@@ -61,6 +73,14 @@ class DecoratedIterable {
61
73
}
62
74
return result ;
63
75
}
76
+
77
+ /**
78
+ * @param {number } limit
79
+ * @return {DecoratedIterable<T> }
80
+ */
81
+ limit ( limit ) {
82
+ return new DecoratedIterable ( limitIt ( limit , this ) ) ;
83
+ }
64
84
}
65
85
66
86
module . exports = {
@@ -73,4 +93,4 @@ module.exports = {
73
93
decorateIt ( iter ) {
74
94
return new DecoratedIterable ( iter ) ;
75
95
}
76
- } ;
96
+ } ;
You can’t perform that action at this time.
0 commit comments