File: feedback_order.py

package info (click to toggle)
automat 25.4.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 492 kB
  • sloc: python: 3,657; makefile: 15
file content (34 lines) | stat: -rw-r--r-- 659 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import dataclasses
import typing

from automat import TypeMachineBuilder


class Inputs(typing.Protocol):
    def compute(self) -> int: ...
    def behavior(self) -> None: ...
class Nothing: ...


builder = TypeMachineBuilder(Inputs, Nothing)
start = builder.state("start")


@start.upon(Inputs.compute).loop()
def three(inputs: Inputs, core: Nothing) -> int:
    return 3


# begin computations
computations = []


@start.upon(Inputs.behavior).loop()
def behave(inputs: Inputs, core: Nothing) -> None:
    computations.append(inputs.compute)


machineFactory = builder.build()
machineFactory(Nothing()).behavior()
print(computations[0]())
# end computations