def eq

yaml-for-bend@0.1.1.0 · value.bend:31

import yaml-for-bend@0.1.1.0/value.bend as Value
import Base

31# Whether two values are the same: same kinds, same texts, same items and
32# entries in the same order.
33def eq(a: Yaml, b: Yaml) -> Bool:
34  match a:
35    case Null{}:
36      match b:
37        case Null{}:
38          True{}
39        case _:
40          False{}
41    case Boolean{x}:
42      match b:
43        case Boolean{y}:
44          same.bool(x, y)
45        case _:
46          False{}
47    case Int{x}:
48      match b:
49        case Int{y}:
50          String.eq(x, y)
51        case _:
52          False{}
53    case Float{x}:
54      match b:
55        case Float{y}:
56          String.eq(x, y)
57        case _:
58          False{}
59    case Str{x}:
60      match b:
61        case Str{y}:
62          String.eq(x, y)
63        case _:
64          False{}
65    case Seq{xs}:
66      match xs:
67        case Nil{}:
68          match b:
69            case Seq{ys}:
70              List.is_empty(&2, Yaml, ys)
71            case _:
72              False{}
73        case Con{x, xt}:
74          match b:
75            case Seq{ys}:
76              match ys:
77                case Nil{}:
78                  False{}
79                case Con{y, yt}:
80                  Bool.and(eq(x, y), eq(Seq{xt}, Seq{yt}))
81            case _:
82              False{}
83    case Mapping{xs}:
84      match xs:
85        case Nil{}:
86          match b:
87            case Mapping{ys}:
88              List.is_empty(&2, Entry, ys)
89            case _:
90              False{}
91        case Con{Entry{xk, xv}, xt}:
92          match b:
93            case Mapping{ys}:
94              match ys:
95                case Nil{}:
96                  False{}
97                case Con{Entry{yk, yv}, yt}:
98                  Bool.and(Bool.and(eq(xk, yk), eq(xv, yv)), eq(Mapping{xt}, Mapping{yt}))
99            case _:
100              False{}
101    case Tagged{s, x}:
102      match b:
103        case Tagged{t, y}:
104          Bool.and(String.eq(s, t), eq(x, y))
105        case _:
106          False{}

Uses (8)

Used by (1)