Skip to content

Commit d4888e4

Browse files
finish documentation of src/map
1 parent 8d6a0c6 commit d4888e4

19 files changed

+119
-24
lines changed

src/map/_zip.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { list , map , iter , _next } from '..' ;
32

43
/**

src/map/_zip2.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { iter } from '..' ;
32

43
/**

src/map/combinations.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import { list , range , pick } from '..' ;
22

33
/**
4-
* @example combinations('ABCD', 2) // AB AC AD BC BD CD
5-
* @example combinations(range(4), 3) // 012 013 023 123
4+
* Yields all combinations of each possible choice of <code>r</code> elements
5+
* of the input iterable.
6+
*
7+
* @example
8+
* // AB AC AD BC BD CD
9+
* combinations('ABCD', 2)
10+
*
11+
* @example
12+
* // 012 013 023 123
13+
* combinations(range(4), 3)
14+
*
15+
* @param {Iterable} iterable - The input iterable.
16+
* @param {Number} r - The size of the combinations to generate.
17+
* @returns {Iterator}
618
*/
7-
819
export function* combinations ( iterable , r ) {
920

1021
let pool = list( iterable ) ;

src/map/combinationswithrepetition.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import { list , nrepeat , pick } from '..' ;
22

33
/**
4-
* @example combinationswithrepetition('ABC', 1) // A B C
5-
* @example combinationswithrepetition(range(3), 2) // 00 01 02 11 12 22
4+
* Yields all combinations, with repetitions, of each possible choice of
5+
* <code>r</code> elements of the input iterable.
6+
*
7+
* @example
8+
* // A B C
9+
* combinationswithrepetition('ABC', 1)
10+
*
11+
* @example
12+
* // 00 01 02 11 12 22
13+
* combinationswithrepetition(range(3), 2)
14+
*
15+
* @param {Iterable} iterable - The input iterable.
16+
* @param {Number} r - The size of the combinations to generate.
17+
* @returns {Iterator}
618
*/
719

820
export function* combinationswithrepetition ( iterable , r ) {

src/map/compress.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
21
import { _zip2 } from '..' ;
32

3+
/**
4+
* Filters the first input iterable according to truthy and flasy values from a
5+
* second input iterable. The ith element of the first input iterable is output
6+
* if and only if the ith element of the second input iterable is truthy.
7+
*
8+
* @param {Iterable} iterable - The first input iterable to filter.
9+
* @param {Iterable} selector - The second input iterable containing the truthy and falsy
10+
* values.
11+
* @returns {Iterator}
12+
*/
413
export function* compress ( iterable , selector ) {
514

615
for ( let [ take , item ] of _zip2( selector , iterable ) ) {

src/map/dropwhile.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
21
import { iter } from '..' ;
32

3+
/**
4+
* Drop elements of the input iterable while the current element satisfies the
5+
* input predicate.
6+
*
7+
* @param {Function} predicate - The input predicate.
8+
* @param {Iterable} iterable - The input iterable.
9+
* @returns {Iterator}
10+
*/
411
export function* dropwhile ( predicate , iterable ) {
512

613
let iterator = iter( iterable ) ;

src/map/filter.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Yields all elements from input iterable that verify a given predicate.
43
*

src/map/group.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
21
import { iter } from '..' ;
32

3+
/**
4+
* Yields elements of the input iterable by grouping them into tuples
5+
* consecutive elements from the same equivalence class.
6+
*
7+
* @param {Function} key - The function used to determine the equivalence class
8+
* of an element.
9+
* @param {Iterable} iterable - The input iterable.
10+
* @returns {Iterator}
11+
*/
412
export function* group ( key , iterable ) {
513

614
let iterator = iter( iterable ) ;
@@ -48,4 +56,8 @@ export function* group ( key , iterable ) {
4856

4957
}
5058

59+
/**
60+
* Same as {@link group}.
61+
* @function groupby
62+
*/
5163
export const groupby = group ;

src/map/map.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
1+
/**
2+
* Applies a given callable to each of the elements of the input iterable.
3+
*
4+
* @example
5+
* // return [ 0 , 1 , 4 , 9 ]
6+
* list( map( x => x**2 , range( 4 ) ) ) ;
7+
*
8+
* @param {Function} callable - The callable to use.
9+
* @param {Iterable} iterable - The input iterable.
10+
* @returns {Iterator}
11+
*/
212
export function* map ( callable , iterable ) {
313

414
for ( let item of iterable ) yield callable( item ) ;

src/map/nrepeat.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Repeats the input item a few times. Returns an iterator that yields the input
43
* item a fixed number of times.

src/map/product.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { list , map , _product , ncycle , reversed } from '..' ;
32

43
/**

src/map/repeat.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Repeats the input item endlessly. Returns an iterator that yields the input
43
* item over and over again.

src/map/reversed.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
1+
/**
2+
* Yields elements of the input iterable in reverse order.
3+
*
4+
* @param {Iterable} iterable - The input iterable.
5+
* @returns {Iterator} - The input iterable, reversed.
6+
*/
27
export function* reversed ( iterable ) {
38

49
let buffer = [ ] ;

src/map/slice.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
21
import { iter } from '..' ;
32

3+
/**
4+
* Same as
5+
* <code>map( [ i , x ] => x , filter( [ i , x ] => (new Set( range( start ,
6+
* stop , step ) ) ).has( i ) , enumerate( iterable ) ) );</code>.
7+
*
8+
* @param {Iterable} iterable - The input iterable.
9+
* @param {Number} start - Where to start the slice.
10+
* @param {Number} stop - Where to stop the slice.
11+
* @param {Number} step - The step of the slice.
12+
* @returns {Iterator}
13+
*/
414
export function* slice ( iterable , start , stop , step ) {
515

616
let iterator = iter( iterable ) ;

src/map/sorted.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
21
import { list } from '../base/list' ;
32

3+
/**
4+
* Outputs an array containing the elements of the input iterable sorted
5+
* according to a given comparison function.
6+
*
7+
* @param {Function} compare - The comparison function to use. This function
8+
* must be 2-ary. It must return -1, 0, or 1 depending whether the first
9+
* parameter is, respectively, less than, equal to, or greater than the second
10+
* parameter.
11+
* @param {Iterable} iterable - The input iterable.
12+
* @returns {Array} - The input iterable, sorted.
13+
*/
414
export function sorted ( compare , iterable ) {
515

616
return list( iterable ).sort( compare ) ;

src/map/starmap.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
1+
/**
2+
* Same as {@link map} but allows multiple arguments callable functions.
3+
*
4+
* @example
5+
* // return [ 0 , 1 , 4 , 9 ]
6+
* list( starmap( ( x , y ) => x*y , zip( range( 4 ) , range( 4 ) ) ) ;
7+
*
8+
* @param {Function} callable - The callable to use.
9+
* @param {Iterable} iterable - The input iterable.
10+
* @returns {Iterator}
11+
*/
212
export function* starmap ( callable , iterable ) {
313

4-
for ( let item of iterable ) yield callable.apply( null , item ) ;
5-
//for ( let args of iterable ) yield callable( ...args ) ;
14+
for ( let args of iterable ) yield callable.apply( null , args ) ;
15+
//for ( let args of iterable ) yield callable( ... ) ;
616

717
}

src/map/takewhile.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
1+
/**
2+
* Output elements of the input iterable while the current element satisfies the
3+
* input predicate.
4+
*
5+
* @param {Function} predicate - The input predicate.
6+
* @param {Iterable} iterable - The input iterable.
7+
* @returns {Iterator}
8+
*/
29
export function* takewhile ( predicate , iterable ) {
310

411
for ( let item of iterable ) {

src/map/zip.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { _zip } from './_zip' ;
32

43
/**

src/map/ziplongest.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { _ziplongest } from './_ziplongest' ;
32

43
/**

0 commit comments

Comments
 (0)