@@ -63,6 +63,8 @@ Since this works with async iterators it requires node 10 or higher.
63
63
- [ ` pipeline() ` ] ( #pipeline )
64
64
- [ ` reduce() ` ] ( #reduce )
65
65
- [ ` take() ` ] ( #take )
66
+ - [ ` takeLast() ` ] ( #takelast )
67
+ - [ ` takeWhile() ` ] ( #takewhile )
66
68
- [ ` tap() ` ] ( #tap )
67
69
- [ ` throttle() ` ] ( #throttle )
68
70
- [ ` time() ` ] ( #time )
@@ -512,6 +514,45 @@ const topFive = await collect(take(5, getPokemon()))
512
514
// first five pokemon
513
515
` ` `
514
516
517
+ ### takeLast
518
+
519
+ ` ` ` ts
520
+ function takeLast<T>(count: number, iterable: AsyncIterable<T>): AsyncIterableIterator<T>
521
+ function takeLast<T>(count: number, iterable: Iterable<T>): IterableIterator<T>
522
+ ` ` `
523
+
524
+ Returns a new iterator that reads a specific number of items from the end of ` iterable ` once it has completed . When used with generators it advances the generator , when used with arrays it gets a new iterator and starts from the beginning .
525
+
526
+ ` ` ` ts
527
+ import { pipeline, takeLast, collect } from 'streaming-iterables'
528
+ import { getPokemon } from 'iterable-pokedex'
529
+
530
+ const bottomFive = await collect(takeLast(5, getPokemon()))
531
+ // last five pokemon
532
+ ` ` `
533
+
534
+ ### takeWhile
535
+
536
+ ` ` ` ts
537
+ function takeWhile<T, S extends T>(predicate: (data: T) => data is S, iterable: AnyIterable<T>): AsyncGenerator<S>;
538
+ ` ` `
539
+
540
+ Takes a ` predicate ` and a ` iterable ` , and returns a new async iterator of the same type containing the members of the given iterable until the ` predicate ` returns false .
541
+
542
+ ` ` ` ts
543
+ import { takeWhile } from 'streaming-iterables'
544
+ import { getPokemon } from 'iterable-pokedex'
545
+
546
+ const firstSlowOnes = takeWhile(pokemon => pokemon.baseStats.speed < 100)
547
+
548
+ for await (const pokemon of firstSlowOnes(getPokemon())) {
549
+ console.log(pokemon)
550
+ }
551
+ // Abomasnow
552
+ // Abra
553
+ // Absol
554
+ ` ` `
555
+
515
556
### tap
516
557
517
558
` ` ` ts
0 commit comments