Skip to content

Commit bd501de

Browse files
more documentation
1 parent 173c95f commit bd501de

File tree

10 files changed

+102
-0
lines changed

10 files changed

+102
-0
lines changed

src/base/_count.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Yields increasing or decreasing sequences of numbers. The starting value
3+
* and the step between separating output values can be chosen.
4+
*
5+
* @example
6+
* // equivalent to list( range( 7 ) )
7+
* list( head( _count( 0 , 1 ) , 7 ) ) ;
8+
*
9+
* @example
10+
* // returns [0,-1,-2,-3,-4]
11+
* list( head( _count( 0 , -1 ) , 5 ) ) ;
12+
*
13+
* @param {Number} start - The starting value.
14+
* @param {Number} step - The step between the values.
15+
* @returns {Iterator}
16+
*/
117
export function* _count ( start , step ) {
218

319
while ( true ) {

src/base/_next.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* Returns the next event of the input iterator.
3+
*
4+
* @param {Iterator} iterator - The input iterator.
5+
* @returns {{done: Boolean, value: Object}}
6+
*/
17
export function _next ( iterator ) {
28

39
return iterator.next( ) ;

src/base/_range.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* Yields values in a range, separated by a fixed constant called step. If
3+
* this step is negative, the range has to be given in reverse order, that is,
4+
* largest value first, smallest value second.
5+
*
6+
* @param {Number} start - The starting value.
7+
* @param {Number} stop - The stopping value.
8+
* @param {Number} step - The step value.
9+
* @returns {Iterator}
10+
*/
111
export function* _range ( start , stop , step ) {
212

313
if ( step < 0 ) {

src/base/by.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { iter } from './iter' ;
22
import { range } from './range' ;
33

4+
/**
5+
* Yields elements of the input iterable by grouping them into tuples of a
6+
* given size.
7+
*
8+
* @param {Iterable} iterable - The input iterable.
9+
* @param {Number} n - The size of the yielded tuples.
10+
* @returns {Iterator}
11+
*/
412
export function* by ( iterable , n ) {
513

614
const iterator = iter( iterable ) ;

src/base/consume.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* Consumes a given number of iterations of the input iterator.
3+
*
4+
* @param {Iterator} iterator - The input iterator.
5+
* @param {Number} n - The number of iterations to consume.
6+
*
7+
*/
18
export function consume ( iterator , n ) {
29

310
while ( n --> 0 && !iterator.next().done ) ;

src/base/count.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
import { _count } from './_count' ;
22

3+
/**
4+
* Yields increasing or decreasing sequences of numbers. The starting value
5+
* and the step between separating output values can be chosen. Both parameters are
6+
* optional. The default for the starting value is <code>0</code>. The default
7+
* for the step between separating output values is <code>1</code>.
8+
*
9+
* @example
10+
* // equivalent to list( range( 7 ) )
11+
* list( head( count( ) , 7 ) ) ;
12+
*
13+
* @example
14+
* // returns [0,-1,-2,-3,-4]
15+
* list( head( count( 0 , -1 ) , 5 ) ) ;
16+
*
17+
* @param {Number} [start=0] - The starting value.
18+
* @param {Number} [step=1] - The step between the values.
19+
* @returns {Iterator}
20+
*/
321
export function count ( start = 0 , step = 1 ) {
422

523
return _count( start , step ) ;

src/base/cycle.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* Cycles through the input iterable.
3+
*
4+
* @example
5+
* // returns [0,1,0,1,0,1,0]
6+
* list(head(cycle(range(2)),7)) ;
7+
*
8+
* @param {Iterable} iterable - The input iterable.
9+
* @returns {Iterator}
10+
*
11+
*/
112
export function* cycle ( iterable ) {
213

314
let buffer = [ ] ;

src/base/drop.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { iter } from './iter' ;
22
import { consume } from './consume' ;
33
import { tail } from './tail' ;
44

5+
/**
6+
* Drops the first <code>n</code> elements of the input iterable.
7+
*
8+
* @param {Iterable} iterable - The input iterable.
9+
* @param {Number} n - The number of elements to drop.
10+
* @returns {Iterator}
11+
*/
512
export function drop ( iterable , n ) {
613

714
if ( n < 0 ) return tail( iterable , -n ) ;

src/base/next.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { StopIteration } from './StopIteration' ;
22

3+
/**
4+
* Returns the next value of the input iterator. If there the iterator is
5+
* exhausted, throws a {@link StopIteration}.
6+
*
7+
* @param {Iterator} iterator - The input iterator.
8+
* @returns {Object}
9+
*/
310
export function next ( iterator ) {
411

512
const x = iterator.next( ) ;

src/base/range.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import { _range } from './_range' ;
22

3+
/**
4+
* Yields values in a range, separated by a fixed constant called step. If this
5+
* step is negative, the range has to be given in reverse order, that is,
6+
* largest value first, smallest value second. Both the starting value and the
7+
* step value are optional. By default the starting value is <code>0</code>.
8+
* The default for the step value is <code>1</code>.
9+
*
10+
* @param {Number} [start=0] - The starting value.
11+
* @param {Number} stop - The stopping value.
12+
* @param {Number} [step=1] - The step value.
13+
* @returns {Iterator}
14+
*/
315
export function range ( start , stop , step ) {
416

517
if ( stop === undefined ) return _range( 0 , start , 1 ) ;

0 commit comments

Comments
 (0)