src/ez/key.bend
ezx@1.11.0.0 · 67 lines · 9 definitions
1
2
3
4
5
6import Base
7
8
9type Stamp is Data:
10 Stamp{rev: String, file: String, bend: String}
11
12
13def none() -> Stamp:
14 Stamp{"", "", ""}
15
16
17def show(key: Stamp) -> String:
18 match key:
19 case Stamp{+r, +f, +b}:
20 r ++ "\n" ++ f ++ "\n" ++ b ++ "\n"
21
22
23
24def read.third(+rev: String, +file: String, ls: List<&2, String>) -> Stamp:
25 match ls:
26 case []:
27 none()
28 case +b <> t:
29 match t:
30 case []:
31 Stamp{rev, file, b}
32 case _h <> _t:
33 none()
34
35def read.second(+rev: String, ls: List<&2, String>) -> Stamp:
36 match ls:
37 case []:
38 none()
39 case +f <> t:
40 read.third(rev, f, t)
41
42def read.lines(ls: List<&2, String>) -> Stamp:
43 match ls:
44 case []:
45 none()
46 case +r <> t:
47 read.second(r, t)
48
49
50def read(+text: String) -> Stamp:
51 read.lines(String.split(text, '\n'))
52
53
54
55def checkout(+was: String, +now: String) -> Bool:
56 Bool.and(Bool.not(String.is_empty(now)), String.eq(was, now))
57
58
59
60def reuse(was: Stamp, now: Stamp) -> Bool:
61 match was:
62 case Stamp{+r0, +f0, +b0}:
63 match now:
64 case Stamp{+r1, +f1, +b1}:
65 Bool.and(Bool.not(String.is_empty(r1)),
66 Bool.and(String.eq(r0, r1),
67 Bool.and(String.eq(f0, f1), String.eq(b0, b1))))