Skip to content
Newer
Older
100644 51 lines (40 sloc) 2.11 KB
509757b @bjouhier improved doc tool
bjouhier authored
1
2 # Streamline built-ins
3
275c5d9 @bjouhier reviewed API documentation
bjouhier authored
4 ## Array functions
ae31fe9 @bjouhier reviewed API documentation
bjouhier authored
5
6 These functions are asynchronous variants of the EcmaScript 5 Array functions.
509757b @bjouhier improved doc tool
bjouhier authored
7
8 Common Rules:
9
10 These variants are postfixed by an underscore.
11 They take the `_` callback as first parameter.
ae31fe9 @bjouhier reviewed API documentation
bjouhier authored
12 They pass the `_` callback as first argument to their `fn` callback.
509757b @bjouhier improved doc tool
bjouhier authored
13 Most of them have an optional `options` second parameter which controls the level of
ae31fe9 @bjouhier reviewed API documentation
bjouhier authored
14 parallelism. This `options` parameter may be specified either as `{ parallel: par }`
15 where `par` is an integer, or directly as a `par` integer value.
509757b @bjouhier improved doc tool
bjouhier authored
16 The `par` values are interpreted as follows:
17
18 * If absent or equal to 1, execution is sequential.
19 * If > 1, at most `par` operations are parallelized.
20 * if 0, a default number of operations are parallelized.
ae31fe9 @bjouhier reviewed API documentation
bjouhier authored
21 This default is defined by `flows.funnel.defaultSize` (4 by default - see `flows` module).
509757b @bjouhier improved doc tool
bjouhier authored
22 * If < 0 or Infinity, operations are fully parallelized (no limit).
23
ae31fe9 @bjouhier reviewed API documentation
bjouhier authored
24 Functions:
509757b @bjouhier improved doc tool
bjouhier authored
25
26 * `array.forEach_(_[, options], fn[, thisObj])`
27 `fn` is called as `fn(_, elt, i)`.
28 * `result = array.map_(_[, options], fn[, thisObj])`
29 `fn` is called as `fn(_, elt, i)`.
30 * `result = array.filter_(_[, options], fn[, thisObj])`
31 `fn` is called as `fn(_, elt)`.
32 * `bool = array.every_(_[, options], fn[, thisObj])`
33 `fn` is called as `fn(_, elt)`.
34 * `bool = array.some_(_[, options], fn[, thisObj])`
35 `fn` is called as `fn(_, elt)`.
ae31fe9 @bjouhier reviewed API documentation
bjouhier authored
36 * `result = array.reduce_(_, fn, val[, thisObj])`
509757b @bjouhier improved doc tool
bjouhier authored
37 `fn` is called as `val = fn(_, val, elt, i, array)`.
ae31fe9 @bjouhier reviewed API documentation
bjouhier authored
38 * `result = array.reduceRight_(_, fn, val[, thisObj])`
509757b @bjouhier improved doc tool
bjouhier authored
39 `fn` is called as `val = fn(_, val, elt, i, array)`.
ae31fe9 @bjouhier reviewed API documentation
bjouhier authored
40 * `array = array.sort_(_, compare [, beg [, end]])`
4298d7a @bjouhier cosmetic doc fixes
bjouhier authored
41 `compare` is called as `cmp = compare(_, elt1, elt2)`.
42 Note: this function _changes_ the original array (and returns it).
509757b @bjouhier improved doc tool
bjouhier authored
43
275c5d9 @bjouhier reviewed API documentation
bjouhier authored
44 ## Function functions
ae31fe9 @bjouhier reviewed API documentation
bjouhier authored
45
46 * `result = fn.apply_(_, thisObj, args[, index])`
47 Helper to use `Function.prototype.apply` inside streamlined functions.
509757b @bjouhier improved doc tool
bjouhier authored
48 Equivalent to `result = fn.apply(thisObj, argsWith_)` where `argsWith_` is
ae31fe9 @bjouhier reviewed API documentation
bjouhier authored
49 a modified `args` in which the callback has been inserted at `index`
94194ec @bjouhier fixed #102 (fn.apply_ accepts -1 as index value - minor API improvement)
bjouhier authored
50 (at the end of the argument list if `index` is omitted or negative).
Something went wrong with that request. Please try again.