Skip to content

Commit eb63890

Browse files
test tee with infinite sequences
1 parent 46cb832 commit eb63890

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/base/tee.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { list } from './list' ;
33
import { map } from '../map/map' ;
44

55
/**
6-
* Returns <code>n</code> copies of the input iterable.
6+
* Returns <code>n</code> copies of the input iterable. Note that if the input
7+
* iterable is an iterator, then it must be discarded by the caller after
8+
* calling tee.
79
*
810
* @param {Iterable} iterable - The input iterable.
911
* @param {Number} n - The number of copies to make.

test/src/base/tee.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import test from 'ava' ;
22

3+
import { list , map , count , range , head , tee } from '../../..' ;
34

4-
import { list , map , tee } from '../../..' ;
55
test( "tee", t => {
66

7-
87
const x = ( iterable , n , expected ) => {
98
t.deepEqual( list( map( list , tee( iterable , n ) ) ) , expected ) ;
109
};
@@ -20,3 +19,12 @@ test( "tee", t => {
2019
x( [5, 7], 2, [[5, 7],[5, 7]] );
2120

2221
});
22+
23+
test( "tee of infinite sequence" , t => {
24+
25+
for ( const it of tee( count( ) , 10 ) ) {
26+
t.deepEqual( list( head( it , 1000 ) ) , list( range( 1000 ) ) ) ;
27+
t.deepEqual( list( head( it , 100 ) ) , list( range( 1000, 1100 ) ) ) ;
28+
}
29+
30+
} ) ;

0 commit comments

Comments
 (0)