@duplojs/agents-kit 0.1.0-beta.8 → 0.1.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/API/10-lang/10-common/10-asyncLoop.ts +4 -6
- package/docs/API/10-lang/10-common/10-asyncLoopAccumulator.ts +40 -0
- package/docs/API/10-lang/10-common/10-loop.ts +5 -7
- package/docs/API/10-lang/10-common/10-loopAccumulator.ts +35 -0
- package/docs/API/10-lang/10-common/10-loopAccumulatorFrom.ts +29 -0
- package/docs/API/10-lang/10-common/index.llms.md +14 -2
- package/docs/API/10-lang/10-generator/10-asyncLoop.ts +11 -20
- package/docs/API/10-lang/10-generator/10-asyncLoopAccumulator.ts +40 -0
- package/docs/API/10-lang/10-generator/10-loop.ts +11 -20
- package/docs/API/10-lang/10-generator/10-loopAccumulator.ts +33 -0
- package/docs/API/10-lang/10-generator/10-loopAccumulatorFrom.ts +30 -0
- package/docs/API/10-lang/10-generator/index.llms.md +14 -2
- package/docs/API/20-server/10-file/10-appendFile.ts +50 -0
- package/docs/API/20-server/10-file/10-appendTextFile.ts +49 -0
- package/docs/API/20-server/10-file/10-copy.ts +50 -0
- package/docs/API/20-server/10-file/10-createEntryInterface.ts +13 -0
- package/docs/API/20-server/10-file/10-createFileInterface.ts +22 -0
- package/docs/API/20-server/10-file/10-createFolderInterface.ts +20 -0
- package/docs/API/20-server/10-file/10-createUnknownEntryInterface.ts +13 -0
- package/docs/API/20-server/10-file/10-ensureDirectory.ts +39 -0
- package/docs/API/20-server/10-file/10-ensureFile.ts +40 -0
- package/docs/API/20-server/10-file/10-exists.ts +36 -0
- package/docs/API/20-server/10-file/10-link.ts +51 -0
- package/docs/API/20-server/10-file/10-linkStat.ts +37 -0
- package/docs/API/20-server/10-file/10-makeDirectory.ts +41 -0
- package/docs/API/20-server/10-file/10-makeTemporaryDirectory.ts +35 -0
- package/docs/API/20-server/10-file/10-makeTemporaryFile.ts +40 -0
- package/docs/API/20-server/10-file/10-move.ts +51 -0
- package/docs/API/20-server/10-file/10-readDirectory.ts +52 -0
- package/docs/API/20-server/10-file/10-readFile.ts +38 -0
- package/docs/API/20-server/10-file/10-readJsonFile.ts +38 -0
- package/docs/API/20-server/10-file/10-readLink.ts +37 -0
- package/docs/API/20-server/10-file/10-readTextFile.ts +38 -0
- package/docs/API/20-server/10-file/10-realPath.ts +36 -0
- package/docs/API/20-server/10-file/10-relocate.ts +51 -0
- package/docs/API/20-server/10-file/10-remove.ts +40 -0
- package/docs/API/20-server/10-file/10-rename.ts +43 -0
- package/docs/API/20-server/10-file/10-setMode.ts +37 -0
- package/docs/API/20-server/10-file/10-setOwner.ts +38 -0
- package/docs/API/20-server/10-file/10-setTime.ts +42 -0
- package/docs/API/20-server/10-file/10-stat.ts +37 -0
- package/docs/API/20-server/10-file/10-symlink.ts +49 -0
- package/docs/API/20-server/10-file/10-truncate.ts +41 -0
- package/docs/API/20-server/10-file/10-walkDirectory.ts +75 -0
- package/docs/API/20-server/10-file/10-writeFile.ts +50 -0
- package/docs/API/20-server/10-file/10-writeJsonFile.ts +41 -0
- package/docs/API/20-server/10-file/10-writeTextFile.ts +49 -0
- package/docs/API/20-server/10-file/index.llms.md +144 -0
- package/docs/API/20-server/10-file/index.md +3 -0
- package/docs/API/20-server/20-common/10-environmentVariable.ts +57 -0
- package/docs/API/20-server/20-common/10-environmentVariableOrThrow.ts +21 -0
- package/docs/API/20-server/20-common/10-exitProcess.ts +9 -0
- package/docs/API/20-server/20-common/10-getCurrentDirectoryName.ts +10 -0
- package/docs/API/20-server/20-common/10-getCurrentWorkDirectory.ts +10 -0
- package/docs/API/20-server/20-common/10-getCurrentWorkDirectoryOrThrow.ts +10 -0
- package/docs/API/20-server/20-common/10-getProcessArguments.ts +10 -0
- package/docs/API/20-server/20-common/10-setCurrentWorkingDirectory.ts +14 -0
- package/docs/API/20-server/20-common/10-setCurrentWorkingDirectoryOrThrow.ts +12 -0
- package/docs/API/20-server/20-common/index.llms.md +40 -0
- package/docs/API/20-server/20-common/index.md +3 -0
- package/docs/API/20-server/30-dataStructure/10-file.ts +14 -0
- package/docs/API/20-server/30-dataStructure/10-fileExist.ts +27 -0
- package/docs/API/20-server/30-dataStructure/10-folder.ts +14 -0
- package/docs/API/20-server/30-dataStructure/10-folderExist.ts +14 -0
- package/docs/API/20-server/30-dataStructure/10-mimeType.ts +14 -0
- package/docs/API/20-server/30-dataStructure/10-size.ts +32 -0
- package/docs/API/20-server/30-dataStructure/index.llms.md +28 -0
- package/docs/API/20-server/30-dataStructure/index.md +3 -0
- package/docs/API/20-server/40-command/10-create.ts +39 -0
- package/docs/API/20-server/40-command/10-createArgument.ts +39 -0
- package/docs/API/20-server/40-command/10-createArrayOption.ts +36 -0
- package/docs/API/20-server/40-command/10-createBooleanOption.ts +28 -0
- package/docs/API/20-server/40-command/10-createOption.ts +46 -0
- package/docs/API/20-server/40-command/10-exec.ts +51 -0
- package/docs/API/20-server/40-command/10-execOptions.ts +30 -0
- package/docs/API/20-server/40-command/index.llms.md +32 -0
- package/docs/API/20-server/40-command/index.md +3 -0
- package/docs/API/20-server/index.md +3 -0
- package/docs/API.llms.md +20 -0
- package/package.json +14 -14
- package/skills/fundamental/SKILL.md +3 -1
- package/skills/fundamental/references/examples/iterations.ts +26 -13
- package/skills/fundamental/references/iterations.md +5 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommand.createOption
|
|
3
|
+
*
|
|
4
|
+
* Déclarer une option à valeur décodée par une data structure.
|
|
5
|
+
*/
|
|
6
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
7
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
8
|
+
import * as DSCommand from "@duplojs/server/command";
|
|
9
|
+
|
|
10
|
+
const command = DSCommand.create(
|
|
11
|
+
"generate",
|
|
12
|
+
{
|
|
13
|
+
options: [
|
|
14
|
+
DSCommand.createOption(
|
|
15
|
+
"format",
|
|
16
|
+
DDataStructure.literal(["json", "text"]),
|
|
17
|
+
{
|
|
18
|
+
required: true,
|
|
19
|
+
aliases: ["f"],
|
|
20
|
+
},
|
|
21
|
+
),
|
|
22
|
+
DSCommand.createOption(
|
|
23
|
+
"output",
|
|
24
|
+
DDataStructure.string(),
|
|
25
|
+
),
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
({ options }) => {
|
|
29
|
+
type _CheckFormat = DCommon.ExpectType<
|
|
30
|
+
typeof options.format,
|
|
31
|
+
"json" | "text",
|
|
32
|
+
"strict"
|
|
33
|
+
>;
|
|
34
|
+
type _CheckOutput = DCommon.ExpectType<
|
|
35
|
+
typeof options.output,
|
|
36
|
+
string | undefined,
|
|
37
|
+
"strict"
|
|
38
|
+
>;
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// Une option présente sans valeur est invalide, même lorsqu'elle est facultative.
|
|
43
|
+
|
|
44
|
+
// Les noms et alias doivent éviter les collisions dans la commande ;
|
|
45
|
+
// help et h sont réservés à l’aide intégrée.
|
|
46
|
+
// Les formes --format=json, --format json et -f json sont acceptées.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommand.exec
|
|
3
|
+
*
|
|
4
|
+
* Lire les arguments du processus, valider une commande racine et exécuter son traitement.
|
|
5
|
+
*/
|
|
6
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
7
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
8
|
+
import * as DEither from "@duplojs/lang/either";
|
|
9
|
+
import * as DSCommand from "@duplojs/server/command";
|
|
10
|
+
|
|
11
|
+
declare function generate(source: string, format: "json" | "text"): Promise<void>;
|
|
12
|
+
|
|
13
|
+
const result = await DSCommand.exec(
|
|
14
|
+
{
|
|
15
|
+
displayName: "generator",
|
|
16
|
+
subjects: [
|
|
17
|
+
DSCommand.createArgument(
|
|
18
|
+
"source",
|
|
19
|
+
DDataStructure.string(),
|
|
20
|
+
),
|
|
21
|
+
],
|
|
22
|
+
options: [
|
|
23
|
+
DSCommand.createOption(
|
|
24
|
+
"format",
|
|
25
|
+
DDataStructure.literal(["json", "text"]),
|
|
26
|
+
{ required: true },
|
|
27
|
+
),
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
async({ args, options }) => {
|
|
31
|
+
type _CheckFormat = DCommon.ExpectType<
|
|
32
|
+
typeof options.format,
|
|
33
|
+
"json" | "text",
|
|
34
|
+
"strict"
|
|
35
|
+
>;
|
|
36
|
+
|
|
37
|
+
await generate(args.source, options.format);
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (DEither.isLeft(result)) {
|
|
42
|
+
// Le parsing invalide empêche le callback ; exec affiche le diagnostic.
|
|
43
|
+
const error = DEither.unwrapLeft(result);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Pour un fichier cli.ts exécuté avec tsx :
|
|
47
|
+
// tsx cli.ts ./source --format=json
|
|
48
|
+
// Ici exec définit directement la commande racine : aucun nom de
|
|
49
|
+
// sous-commande ne précède l'argument source.
|
|
50
|
+
// Les noms d'options doivent être uniques dans la commande. subjects
|
|
51
|
+
// contient soit des arguments positionnels, soit des sous-commandes.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommand.execOptions
|
|
3
|
+
*
|
|
4
|
+
* Décoder les options du processus sans déclarer de commande positionnelle.
|
|
5
|
+
*/
|
|
6
|
+
import * as DEither from "@duplojs/lang/either";
|
|
7
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
8
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
9
|
+
import * as DSCommand from "@duplojs/server/command";
|
|
10
|
+
|
|
11
|
+
const result = await DSCommand.execOptions([
|
|
12
|
+
DSCommand.createOption(
|
|
13
|
+
"format",
|
|
14
|
+
DDataStructure.literal(["json", "text"]),
|
|
15
|
+
),
|
|
16
|
+
DSCommand.createBooleanOption("verbose"),
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
if (DEither.hasInformation(result, "success")) {
|
|
20
|
+
const options = DEither.unwrapRight(result);
|
|
21
|
+
|
|
22
|
+
type _CheckFormat = DCommon.ExpectType<
|
|
23
|
+
typeof options.format,
|
|
24
|
+
"json" | "text" | undefined,
|
|
25
|
+
"strict"
|
|
26
|
+
>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// L'aide est également un Right, identifié par log-help ; une erreur est
|
|
30
|
+
// affichée puis renvoyée dans un Left.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
## Command
|
|
2
|
+
|
|
3
|
+
Déclarer et exécuter des commandes CLI et leurs entrées typées.
|
|
4
|
+
|
|
5
|
+
### [DSCommand.create](10-create.ts)
|
|
6
|
+
|
|
7
|
+
Construire une commande nommée à placer dans un arbre de commandes.
|
|
8
|
+
|
|
9
|
+
### [DSCommand.createArgument](10-createArgument.ts)
|
|
10
|
+
|
|
11
|
+
Déclarer un argument positionnel validé et transmis à une commande.
|
|
12
|
+
|
|
13
|
+
### [DSCommand.createArrayOption](10-createArrayOption.ts)
|
|
14
|
+
|
|
15
|
+
Déclarer une option contenant plusieurs valeurs décodées.
|
|
16
|
+
|
|
17
|
+
### [DSCommand.createBooleanOption](10-createBooleanOption.ts)
|
|
18
|
+
|
|
19
|
+
Déclarer un flag représentant la présence d’une option.
|
|
20
|
+
|
|
21
|
+
### [DSCommand.createOption](10-createOption.ts)
|
|
22
|
+
|
|
23
|
+
Déclarer une option à valeur décodée par une data structure.
|
|
24
|
+
|
|
25
|
+
### [DSCommand.exec](10-exec.ts)
|
|
26
|
+
|
|
27
|
+
Lire les arguments du processus, valider une commande racine et exécuter son traitement.
|
|
28
|
+
|
|
29
|
+
### [DSCommand.execOptions](10-execOptions.ts)
|
|
30
|
+
|
|
31
|
+
Décoder les options du processus sans déclarer de commande positionnelle.
|
|
32
|
+
|
package/docs/API.llms.md
CHANGED
|
@@ -58,6 +58,26 @@ Fonctions de manipulation, recherche, validation et transformation des chaînes
|
|
|
58
58
|
|
|
59
59
|
Manipulation et typage des tuples : convertir les garanties de cardinalité en positions typées, puis transformer leurs éléments en conservant leur forme.
|
|
60
60
|
|
|
61
|
+
# @duplojs/server
|
|
62
|
+
|
|
63
|
+
Capacités portables de fichiers, environnement, validation de ressources et commandes CLI.
|
|
64
|
+
|
|
65
|
+
## [File](API/20-server/10-file/index.llms.md)
|
|
66
|
+
|
|
67
|
+
Lire et modifier les ressources du système de fichiers, leurs chemins et leurs métadonnées.
|
|
68
|
+
|
|
69
|
+
## [Common](API/20-server/20-common/index.llms.md)
|
|
70
|
+
|
|
71
|
+
Accéder à la configuration, aux arguments et aux capacités du processus.
|
|
72
|
+
|
|
73
|
+
## [DataStructure](API/20-server/30-dataStructure/index.llms.md)
|
|
74
|
+
|
|
75
|
+
Décoder et valider les interfaces de fichiers et dossiers avec les contraintes serveur.
|
|
76
|
+
|
|
77
|
+
## [Command](API/20-server/40-command/index.llms.md)
|
|
78
|
+
|
|
79
|
+
Déclarer et exécuter des commandes CLI et leurs entrées typées.
|
|
80
|
+
|
|
61
81
|
# @duplojs/json-web-token
|
|
62
82
|
|
|
63
83
|
Politiques JWT réutilisables, signature, chiffrement facultatif et primitives cryptographiques.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duplojs/agents-kit",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "DuploJS",
|
|
@@ -32,19 +32,19 @@
|
|
|
32
32
|
"./docs/API/*/index.llms.md": "./docs/API/*/index.llms.md"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@duplojs/lang": "0.1.0-beta.
|
|
36
|
-
"@duplojs/server": "0.1.0-beta.
|
|
35
|
+
"@duplojs/lang": "0.1.0-beta.9",
|
|
36
|
+
"@duplojs/server": "0.1.0-beta.9"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@duplojs/code-config": "0.1.0-beta.
|
|
40
|
-
"@duplojs/eslint": "0.1.0-beta.
|
|
41
|
-
"@duplojs/form": "0.1.0-beta.
|
|
42
|
-
"@duplojs/http": "0.1.0-beta.
|
|
43
|
-
"@duplojs/json-web-token": "0.1.0-beta.
|
|
44
|
-
"@duplojs/lang": "0.1.0-beta.
|
|
45
|
-
"@duplojs/playwright": "0.1.0-beta.
|
|
46
|
-
"@duplojs/server": "0.1.0-beta.
|
|
47
|
-
"@duplojs/tools": "0.1.0-beta.
|
|
39
|
+
"@duplojs/code-config": "0.1.0-beta.9",
|
|
40
|
+
"@duplojs/eslint": "0.1.0-beta.9",
|
|
41
|
+
"@duplojs/form": "0.1.0-beta.9",
|
|
42
|
+
"@duplojs/http": "0.1.0-beta.9",
|
|
43
|
+
"@duplojs/json-web-token": "0.1.0-beta.9",
|
|
44
|
+
"@duplojs/lang": "0.1.0-beta.9",
|
|
45
|
+
"@duplojs/playwright": "0.1.0-beta.9",
|
|
46
|
+
"@duplojs/server": "0.1.0-beta.9",
|
|
47
|
+
"@duplojs/tools": "0.1.0-beta.9"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
50
|
"@duplojs/code-config": {
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@duplojs/code-config": "0.1.0-beta.
|
|
74
|
-
"@duplojs/eslint": "0.1.0-beta.
|
|
73
|
+
"@duplojs/code-config": "0.1.0-beta.9",
|
|
74
|
+
"@duplojs/eslint": "0.1.0-beta.9",
|
|
75
75
|
"@types/node": "24.13.3",
|
|
76
76
|
"@types/web": "0.0.358",
|
|
77
77
|
"vue": "3.5.43",
|
|
@@ -48,8 +48,10 @@ Ne pas écrire de `for`, de `while` ni leurs variantes. Utiliser :
|
|
|
48
48
|
- `DArray.reduce` pour parcourir un tableau avec un accumulateur ; `DGenerator.reduce` pour un autre itérable.
|
|
49
49
|
- `DGenerator.asyncReduce` pour un parcours asynchrone, y compris sur un tableau.
|
|
50
50
|
- `DCommon.loop` pour une répétition conditionnelle ; `DCommon.asyncLoop` en asynchrone.
|
|
51
|
+
- `DCommon.loopAccumulator` et `DCommon.asyncLoopAccumulator` pour transporter un accumulateur entre les tours d’une répétition conditionnelle.
|
|
52
|
+
- `DGenerator.loop` et `DGenerator.asyncLoop` pour produire une séquence ; leurs variantes `loopAccumulator` transportent aussi un accumulateur.
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
Dans les variantes `loopAccumulator`, transmettre l'état avec `next(nouvelAccumulateur)` ; `DGenerator.loop` et `DGenerator.asyncLoop` utilisent `next` pour émettre des valeurs. Dans `DCommon.loop` et `DCommon.asyncLoop`, `next` poursuit la boucle sans transmettre son argument au tour suivant. Terminer avec `exit`. Avant de créer ou remplacer une boucle, lire [Itérations](references/iterations.md) pour les contrats de ces callbacks. Pour une simple transformation ou sélection, utiliser directement `DArray.map` ou `DArray.filter`.
|
|
53
55
|
|
|
54
56
|
## Valider les entrées et conserver les garanties
|
|
55
57
|
|
|
@@ -63,37 +63,50 @@ const loadedTotal = await DCommon.asyncPipe(
|
|
|
63
63
|
// Chaque chargement est attendu avant le suivant ; la source peut aussi être un AsyncIterable.
|
|
64
64
|
type _CheckLoadedTotal = DCommon.ExpectType<typeof loadedTotal, number, "strict">;
|
|
65
65
|
|
|
66
|
-
const reachedValue = DCommon.
|
|
67
|
-
const current = previousOutput ?? 0;
|
|
68
|
-
|
|
66
|
+
const reachedValue = DCommon.loopAccumulator(0, ({ accumulator, next, exit }) => {
|
|
69
67
|
// La condition est vérifiée avant le traitement, comme dans un while.
|
|
70
|
-
if (
|
|
71
|
-
return exit(
|
|
68
|
+
if (accumulator >= 3) {
|
|
69
|
+
return exit(accumulator);
|
|
72
70
|
}
|
|
73
71
|
|
|
74
|
-
return next(DNumber.sum([
|
|
72
|
+
return next(DNumber.sum([accumulator, 1]));
|
|
75
73
|
});
|
|
76
74
|
|
|
77
|
-
// Résultat : 3. L'état circule dans
|
|
75
|
+
// Résultat : 3. L'état circule dans l'accumulateur de la boucle.
|
|
78
76
|
type _CheckReachedValue = DCommon.ExpectType<typeof reachedValue, number, "strict">;
|
|
79
77
|
|
|
80
78
|
declare function readBatchSize(index: number): Promise<number>;
|
|
81
79
|
|
|
82
|
-
const processedTotal = await DCommon.
|
|
80
|
+
const processedTotal = await DCommon.asyncLoopAccumulator(0, async({
|
|
83
81
|
count,
|
|
84
|
-
|
|
82
|
+
accumulator,
|
|
85
83
|
next,
|
|
86
84
|
exit,
|
|
87
85
|
}) => {
|
|
88
|
-
const current = previousOutput ?? 0;
|
|
89
86
|
const size = await readBatchSize(count);
|
|
90
87
|
|
|
91
|
-
// La première taille nulle termine la lecture ; le
|
|
88
|
+
// La première taille nulle termine la lecture ; exit retourne le total accumulé.
|
|
92
89
|
if (size === 0) {
|
|
93
|
-
return exit(
|
|
90
|
+
return exit(accumulator);
|
|
94
91
|
}
|
|
95
92
|
|
|
96
|
-
return next(DNumber.sum([
|
|
93
|
+
return next(DNumber.sum([accumulator, size]));
|
|
97
94
|
});
|
|
98
95
|
|
|
99
96
|
type _CheckProcessedTotal = DCommon.ExpectType<typeof processedTotal, number, "strict">;
|
|
97
|
+
|
|
98
|
+
const emitted = DArray.from(DGenerator.loop(({ count, next, exit }) => count === 3
|
|
99
|
+
? exit("done")
|
|
100
|
+
: next(count)));
|
|
101
|
+
|
|
102
|
+
// DGenerator.loop émet les sorties de next puis celles de exit.
|
|
103
|
+
type _CheckEmitted = DCommon.ExpectType<typeof emitted, readonly (number | "done")[], "strict">;
|
|
104
|
+
|
|
105
|
+
const emittedWithAccumulator = DArray.from(
|
|
106
|
+
DGenerator.loopAccumulator(0, ({ accumulator, count, next, exit }) => count === 3
|
|
107
|
+
? exit(accumulator)
|
|
108
|
+
: next(accumulator + 1, accumulator)),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// Chaque sortie peut être produite au même moment que le nouvel accumulateur est choisi.
|
|
112
|
+
type _CheckEmittedWithAccumulator = DCommon.ExpectType<typeof emittedWithAccumulator, readonly number[], "strict">;
|
|
@@ -13,7 +13,11 @@ Pour un autre itérable, utiliser `DGenerator.reduce`. `DGenerator.asyncReduce`
|
|
|
13
13
|
|
|
14
14
|
## Répéter jusqu'à une condition
|
|
15
15
|
|
|
16
|
-
`DCommon.loop` fournit `count` depuis zéro et `
|
|
16
|
+
`DCommon.loop` fournit `count` depuis zéro. `next()` continue et `exit(valeur)` retourne le résultat final. La donnée optionnelle de `next` n'est pas transmise au tour suivant ; utiliser `DCommon.loopAccumulator(initial, callback)` lorsque les tours doivent partager un état. Sa callback reçoit `accumulator`, `count`, `next(nouvelAccumulateur)` et `exit(résultat)`. `DCommon.asyncLoop` et `DCommon.asyncLoopAccumulator` offrent les mêmes comportements en attendant la callback asynchrone.
|
|
17
|
+
|
|
18
|
+
`DGenerator.loop(callback)` produit une séquence : chaque `next(...valeurs)` émet les valeurs définies et poursuit la boucle ; `exit(...valeurs)` émet sa dernière séquence puis termine. La callback reçoit `count`, pas la valeur du tour précédent. `DGenerator.asyncLoop` attend les callbacks et résout les valeurs promises avant de les émettre.
|
|
19
|
+
|
|
20
|
+
Les variantes `DGenerator.loopAccumulator(initial, callback)` et `DGenerator.asyncLoopAccumulator(initial, callback)` font circuler un accumulateur avec `next(nouvelAccumulateur, ...valeursÀÉmettre)`. `exit(...valeursÀÉmettre)` termine en émettant les dernières valeurs. Utiliser `DGenerator.loopAccumulatorFrom<Type>(valeur)` pour préserver un type d'accumulateur structuré ou une union.
|
|
17
21
|
|
|
18
22
|
Conserver la condition avant le traitement d'un `while`, après celui d'un `do...while`. Pour une répétition par compteur, utiliser aussi `loop`, sans fabriquer un tableau.
|
|
19
23
|
|