From 846d742893a50603decf5ae77317fda6fee19277 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 4 Jun 2022 09:30:50 +0300 Subject: [PATCH] docs... Signed-off-by: Alex A. Naanou --- README.md | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) 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]] ```