Skip to content

Commit a7e90e9

Browse files
authored
Merge pull request #10665 from pbackus/fix-gh-10540
sumtype: rename 'degrees' to 'value' in example
2 parents f243f64 + 613ec08 commit a7e90e9

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

std/sumtype.d

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ version (D_BetterC) {} else
3232
{
3333
import std.math.operations : isClose;
3434

35-
struct Fahrenheit { double degrees; }
36-
struct Celsius { double degrees; }
37-
struct Kelvin { double degrees; }
35+
struct Fahrenheit { double value; }
36+
struct Celsius { double value; }
37+
struct Kelvin { double value; }
3838

3939
alias Temperature = SumType!(Fahrenheit, Celsius, Kelvin);
4040

@@ -48,29 +48,29 @@ version (D_BetterC) {} else
4848
{
4949
return Fahrenheit(
5050
t.match!(
51-
(Fahrenheit f) => f.degrees,
52-
(Celsius c) => c.degrees * 9.0/5 + 32,
53-
(Kelvin k) => k.degrees * 9.0/5 - 459.4
51+
(Fahrenheit f) => f.value,
52+
(Celsius c) => c.value * 9.0/5 + 32,
53+
(Kelvin k) => k.value * 9.0/5 - 459.4
5454
)
5555
);
5656
}
5757

58-
assert(toFahrenheit(t1).degrees.isClose(98.6));
59-
assert(toFahrenheit(t2).degrees.isClose(212));
60-
assert(toFahrenheit(t3).degrees.isClose(32));
58+
assert(toFahrenheit(t1).value.isClose(98.6));
59+
assert(toFahrenheit(t2).value.isClose(212));
60+
assert(toFahrenheit(t3).value.isClose(32));
6161

6262
// Use ref to modify the value in place.
6363
void freeze(ref Temperature t)
6464
{
6565
t.match!(
66-
(ref Fahrenheit f) => f.degrees = 32,
67-
(ref Celsius c) => c.degrees = 0,
68-
(ref Kelvin k) => k.degrees = 273
66+
(ref Fahrenheit f) => f.value = 32,
67+
(ref Celsius c) => c.value = 0,
68+
(ref Kelvin k) => k.value = 273
6969
);
7070
}
7171

7272
freeze(t1);
73-
assert(toFahrenheit(t1).degrees.isClose(32));
73+
assert(toFahrenheit(t1).value.isClose(32));
7474

7575
// Use a catch-all handler to give a default result.
7676
bool isFahrenheit(Temperature t)

0 commit comments

Comments
 (0)