YamlPair

Constructors

this
this(K key, V value)

Members

Functions

opCmp
int opCmp(typeof(this) rhs)
opCmp
int opCmp(typeof(this) rhs)

Variables

key
YamlAlgebraic key;
value
YamlAlgebraic value;

Examples

1 import mir.ndslice.topology: map;
2 import mir.array.allocation: array;
3 
4 YamlAlgebraic value;
5 
6 // Default
7 assert(value.isNull);
8 assert(value.kind == YamlAlgebraic.Kind.null_);
9 
10 // Boolean
11 value = true;
12 
13 assert(!value.isNull);
14 assert(value == true);
15 assert(value.kind == YamlAlgebraic.Kind.boolean);
16 assert(value.boolean == true);
17 assert(value.get!bool == true);
18 assert(value.get!(YamlAlgebraic.Kind.boolean) == true);
19 
20 // Null
21 value = null;
22 assert(value.isNull);
23 assert(value == null);
24 assert(value.kind == YamlAlgebraic.Kind.null_);
25 assert(value.null_ == null);
26 assert(value.get!(typeof(null)) == null);
27 assert(value.get!(YamlAlgebraic.Kind.null_) == null);
28 
29 // String
30 value = "s";
31 assert(value.kind == YamlAlgebraic.Kind.string);
32 assert(value == "s");
33 assert(value.string == "s");
34 assert(value.get!string == "s");
35 assert(value.get!(YamlAlgebraic.Kind.string) == "s");
36 
37 // Integer
38 value = 4;
39 assert(value.kind == YamlAlgebraic.Kind.integer);
40 assert(value == 4);
41 assert(value != 4.0);
42 assert(value.integer == 4);
43 
44 // Float
45 value = 3.0;
46 assert(value.kind == YamlAlgebraic.Kind.float_);
47 assert(value != 3);
48 assert(value == 3.0);
49 assert(value.float_ == 3.0);
50 assert(value.get!double == 3.0);
51 assert(value.get!(YamlAlgebraic.Kind.float_) == 3.0);
52 
53 // Array
54 YamlAlgebraic[] arr = [0, 1, 2, 3, 4].map!YamlAlgebraic.array;
55 
56 value = arr;
57 assert(value.kind == YamlAlgebraic.Kind.array);
58 assert(value == arr);
59 assert(value.array[3] == 3);
60 
61 // Object
62 value = [1 : "a"].YamlAlgebraic;
63 assert(value.kind == YamlAlgebraic.Kind.object);
64 assert(value.object.pairs == [YamlPair(1, "a")]);
65 assert(value.object[1.YamlAlgebraic] == "a");
66 
67 assert(value == value);
68 assert(value <= value);
69 assert(value >= value);

Meta