-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdoc.go
47 lines (36 loc) · 1.11 KB
/
doc.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
The dfa package implements a deterministic finite automata to define stateful computations
that are easier understood when transitions are specified explicitly. The API is more
interested in using the DFA to clearly define stateful computation, rather than actually
being used to recognize languages.
Importing
import "github.com/lytics/dfa"
Example
Starting = dfa.State("starting")
Finishing = dfa.State("finishing")
Done = dfa.Letter("done")
Repeat = dfa.Letter("repeat")
var errors []error
starting := func() dfa.Letter {
if err := do(); err != nil {
errors = append(errors, err)
return Repeat
} else {
return Done
}
}
finishing := func() {
fmt.Println("all finished")
}
d := dfa.New()
d.SetStartState(Starting)
d.SetTerminalStates(Finishing)
d.SetTransition(Starting, Done, Finishing, finishing)
d.SetTransition(Starting, Repeat, Starting, starting)
final, accepted := d.Run(starting)
...
for _, err := range errors {
...
}
*/
package dfa