diff --git a/README.md b/README.md index 00a90f7..f7b6dd3 100644 --- a/README.md +++ b/README.md @@ -1663,40 +1663,48 @@ can be useful to hide the extended promise API from further code. #### Advanced handler ```bnf -Promise.iter(, ) +Promise.iter(, ) -> +``` -() - -> [ ] +The `` will get passed each resolved `` of the input `` +as soon as it's available/resolved. + +The `` return value is unwrapped into the resulting array, allowing +each call to both remove elements (i.e. returning `[]`) from the resulting +`` as well as insert multiple items (by returning an array of items). + + + +```bnf +() + -> [] + -> [ , .. ] + -> ``` ```bnf - ::= + ::= [] - | [ , .. ] + | [ , .. ] - ::= - [] - | [ , .. ] - | - | + ::= + + | () ``` Example: ```javascript var p = Promise.iter( - // NOTE: if you want an element to explicitly be an array wrap it in - // an array -- like the last element here... - [[1, 2], 3, Promise.resolve(4), [[5, 6]]], + [1, 2, 3, Promise.resolve(4), [5, 6]], function(elem){ return elem % 2 == 0 ? [elem, elem] : elem instanceof Array ? - [elem] + [elem] : [] }) .then(function(lst){ - console.log(lst) // -> [2, 2, 4, 4, [5, 6]] - }) + console.log(lst) }) // -> [2, 2, 4, 4, [5, 6]] ```