Error in docs for 'scan' and 'scanRight'
phormio opened this issue · comments
Phormio commented
The JSDoc for scan
has an example that uses fold
, not scan
:
Lines 120 to 142 in edac822
/** | |
* Returns a list that contains the elements in the list of `as` scanned | |
* left-to-right with the binary function `f` and starting value `s`. | |
* | |
* @summary Scans a list from left to right with a function. | |
* | |
* @example | |
* | |
* F.fold(F.flip(F.prepend), [], [1, 2, 3]) // [[], [1], [2, 1], [3, 2, 1]] | |
* F.fold(F.flip(F.prepend), '', 'foo') // ['', 'f', 'of', 'oof'] | |
* | |
* @curried | |
* @function | |
* @param f A binary function. | |
* @param s A starting value. | |
* @param as A list. | |
* @returns A new list. | |
*/ | |
export const scan = curry((f, s, as) => { | |
const r = [s] | |
fold((b, a) => tap(r.push.bind(r), f(b, a)), s, as) | |
return r | |
}) |
There is a similar error for scanRight
:
Lines 144 to 166 in edac822
/** | |
* Returns a list that contains the elements in the list of `as` scanned | |
* right-to-left with the binary function `f` and starting value `s`. | |
* | |
* @summary Scans a list from right to left with a function. | |
* | |
* @example | |
* | |
* F.foldRight(F.append, [], [1, 2, 3]) // [[3, 2, 1], [3, 2], [3], []] | |
* F.foldRight(F.append, '', 'foo') // ['oof', 'oo', 'o', ''] | |
* | |
* @curried | |
* @function | |
* @param f A binary function. | |
* @param s A starting value. | |
* @param as A list. | |
* @returns A new list. | |
*/ | |
export const scanRight = curry((f, s, as) => { | |
const r = [s] | |
foldRight((a, b) => tap(r.unshift.bind(r), f(a, b)), s, as) | |
return r | |
}) |
Joshua Bassett commented
Oops, thanks for letting me know. Will fix.