@thi.ng/transducers-fsm 2.2.0 → 2.2.2
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/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/index.d.ts +18 -20
- package/index.js +18 -20
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ updated with new features.**
|
|
|
26
26
|
|
|
27
27
|
## About
|
|
28
28
|
|
|
29
|
-
Transducer-based Finite State Machine transformer
|
|
29
|
+
Transducer-based Finite State Machine transformer. This is a support package for [@thi.ng/transducers](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers).
|
|
30
30
|
|
|
31
31
|
This package provides a single function, a general purpose [Finite State
|
|
32
32
|
Machine](https://en.wikipedia.org/wiki/Finite-state_machine) transducer,
|
package/index.d.ts
CHANGED
|
@@ -11,29 +11,27 @@ export interface FSMOpts<T extends FSMState, A, B> {
|
|
|
11
11
|
init: Fn0<T>;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Finite State Machine transducer. Takes an FSM configuration object
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* outputs per consumed input.
|
|
14
|
+
* Finite State Machine transducer. Takes an FSM configuration object and
|
|
15
|
+
* returns a transducer, which processes inputs using the provided state handler
|
|
16
|
+
* functions, which in turn can return any number of outputs per consumed input.
|
|
18
17
|
*
|
|
19
|
-
* Before processing the first input, the FSM state is initialized by
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* based on given inputs.
|
|
18
|
+
* Before processing the first input, the FSM state is initialized by calling
|
|
19
|
+
* the user provided `init()` function, which MUST return a state object with at
|
|
20
|
+
* least a `state` key, whose value is used for dynamic (i.e. stateful) dispatch
|
|
21
|
+
* during input processing. This state object is passed with each input value to
|
|
22
|
+
* the current state handler, which is expected to mutate this object, e.g. to
|
|
23
|
+
* cause state changes based on given inputs.
|
|
26
24
|
*
|
|
27
|
-
* If a state handler needs to "emit" results for downstream processing,
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
25
|
+
* If a state handler needs to "emit" results for downstream processing, it can
|
|
26
|
+
* return an array of values. Any such values are passed on (individually, not
|
|
27
|
+
* as array) to the next reducer in the chain. If a state handler returns `null`
|
|
28
|
+
* or `undefined`, further downstream processing of the current input is
|
|
29
|
+
* skipped.
|
|
32
30
|
*
|
|
33
|
-
* Regardless of return value, if a state handler has caused a state
|
|
34
|
-
*
|
|
35
|
-
* (
|
|
36
|
-
* inputs will be consumed.
|
|
31
|
+
* Regardless of return value, if a state handler has caused a state change to
|
|
32
|
+
* the configured `terminal` state, processing is terminated (by calling
|
|
33
|
+
* [`ensureReduced()`](https://docs.thi.ng/umbrella/transducers/functions/ensureReduced.html))
|
|
34
|
+
* and no further inputs will be consumed.
|
|
37
35
|
*
|
|
38
36
|
* @example
|
|
39
37
|
* ```ts
|
package/index.js
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import { compR } from "@thi.ng/transducers/compr";
|
|
2
2
|
import { ensureReduced, isReduced } from "@thi.ng/transducers/reduced";
|
|
3
3
|
/**
|
|
4
|
-
* Finite State Machine transducer. Takes an FSM configuration object
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* outputs per consumed input.
|
|
4
|
+
* Finite State Machine transducer. Takes an FSM configuration object and
|
|
5
|
+
* returns a transducer, which processes inputs using the provided state handler
|
|
6
|
+
* functions, which in turn can return any number of outputs per consumed input.
|
|
8
7
|
*
|
|
9
|
-
* Before processing the first input, the FSM state is initialized by
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* based on given inputs.
|
|
8
|
+
* Before processing the first input, the FSM state is initialized by calling
|
|
9
|
+
* the user provided `init()` function, which MUST return a state object with at
|
|
10
|
+
* least a `state` key, whose value is used for dynamic (i.e. stateful) dispatch
|
|
11
|
+
* during input processing. This state object is passed with each input value to
|
|
12
|
+
* the current state handler, which is expected to mutate this object, e.g. to
|
|
13
|
+
* cause state changes based on given inputs.
|
|
16
14
|
*
|
|
17
|
-
* If a state handler needs to "emit" results for downstream processing,
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
15
|
+
* If a state handler needs to "emit" results for downstream processing, it can
|
|
16
|
+
* return an array of values. Any such values are passed on (individually, not
|
|
17
|
+
* as array) to the next reducer in the chain. If a state handler returns `null`
|
|
18
|
+
* or `undefined`, further downstream processing of the current input is
|
|
19
|
+
* skipped.
|
|
22
20
|
*
|
|
23
|
-
* Regardless of return value, if a state handler has caused a state
|
|
24
|
-
*
|
|
25
|
-
* (
|
|
26
|
-
* inputs will be consumed.
|
|
21
|
+
* Regardless of return value, if a state handler has caused a state change to
|
|
22
|
+
* the configured `terminal` state, processing is terminated (by calling
|
|
23
|
+
* [`ensureReduced()`](https://docs.thi.ng/umbrella/transducers/functions/ensureReduced.html))
|
|
24
|
+
* and no further inputs will be consumed.
|
|
27
25
|
*
|
|
28
26
|
* @example
|
|
29
27
|
* ```ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/transducers-fsm",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Transducer-based Finite State Machine transformer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.6.
|
|
38
|
-
"@thi.ng/transducers": "^8.3.
|
|
37
|
+
"@thi.ng/api": "^8.6.2",
|
|
38
|
+
"@thi.ng/transducers": "^8.3.28"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@microsoft/api-extractor": "^7.33.7",
|
|
42
|
-
"@thi.ng/testament": "^0.3.
|
|
42
|
+
"@thi.ng/testament": "^0.3.8",
|
|
43
43
|
"rimraf": "^3.0.2",
|
|
44
44
|
"tools": "^0.0.1",
|
|
45
45
|
"typedoc": "^0.23.22",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"status": "completed",
|
|
75
75
|
"year": 2018
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "bc6f7f5e2765bb96fe64db804eaf4b2443b47fc6\n"
|
|
78
78
|
}
|