Skip to content

Commit cc6e4c8

Browse files
committed
Document missing Enumeration methods
1 parent 55b8c01 commit cc6e4c8

File tree

1 file changed

+53
-12
lines changed

1 file changed

+53
-12
lines changed

doc/Type/Enumeration.pod6

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ Returns it as a C<Pair>.
122122
=for code :preamble<<enum Mass<g> >>
123123
say g.pair; # OUTPUT: «g => 1␤»
124124
125+
=head2 method CALL-ME
126+
127+
Defined as:
128+
129+
multi method CALL-ME(|)
130+
131+
Returns an C<Enumeration> instance given an enum value.
132+
133+
enum Mass ( mg => 1/1000, g => 1/1, kg => 1000/1 );
134+
say Mass(1/1000); # OUTPUT: mg
135+
125136
=head2 method pick
126137
127138
Defined as:
@@ -132,7 +143,7 @@ Defined as:
132143
133144
It works on the defined class, selecting one element and eliminating it.
134145
135-
=for code :preamble<enum Norse-gods <Þor Oðin Freija>;>
146+
=for code :preamble«enum Norse-gods <Þor Oðin Freija>;»
136147
say Norse-gods.pick() for ^3; # OUTPUT: «Þor␤Freija␤Oðin␤»
137148
138149
=head2 method roll
@@ -146,7 +157,7 @@ Defined as:
146157
They work on the defined class selecting one or C<n> elements without
147158
eliminating them.
148159
149-
=for code :preamble<enum Norse-gods <Þor Oðin Freija>;>
160+
=for code :preamble«enum Norse-gods <Þor Oðin Freija>;»
150161
say Norse-gods.roll() for ^3; # OUTPUT: «Freija␤Freija␤Oðin␤»
151162
152163
=head2 method pred
@@ -155,7 +166,7 @@ Defined as:
155166
156167
method pred(::?CLASS:D:)
157168
158-
=for code :preamble<enum Norse-gods <Þor Oðin Freija>;>
169+
=for code :preamble«enum Norse-gods <Þor Oðin Freija>;»
159170
say Freija.pred; # OUTPUT: «Oðin␤»
160171
161172
=head2 method succ
@@ -164,9 +175,25 @@ Defined as:
164175
165176
method succ(::?CLASS:D:)
166177
167-
=for code :preamble<enum Norse-gods <Þor Oðin Freija>;>
178+
=for code :preamble«enum Norse-gods <Þor Oðin Freija>;»
168179
say Oðin.succ; # OUTPUT: «Freija␤»
169180
181+
=head2 method Numeric
182+
183+
Defined as:
184+
185+
multi method Numeric(::?CLASS:D:)
186+
187+
Takes a value of an enum and returns it after coercion to C<Numeric>:
188+
189+
enum Numbers ( cool => '42', almost-pi => '3.14', sqrt-n-one => 'i' );
190+
say cool.Numeric; # OUTPUT: «42␤»
191+
say almost-pi.Numeric; # OUTPUT: «3.14␤»
192+
say sqrt-n-one.Numeric; # OUTPUT: «0+1i␤»
193+
194+
Note that if the value cannot be coerced to C<Numeric>, an exception
195+
will be thrown.
196+
170197
=head2 method Int
171198
172199
Defined as:
@@ -175,16 +202,30 @@ Defined as:
175202
176203
Takes a value of an enum and returns it after coercion to C<Int>:
177204
178-
enum Numbers <One Two Three>;
179-
say Two.Int; # OUTPUT: «1␤»
205+
enum Numbers ( cool => '42', almost-pi => '3.14', sqrt-n-one => 'i' );
206+
say cool.Int; # OUTPUT: «42␤»
207+
say almost-pi.Int; # OUTPUT: «3␤»
208+
try say sqrt-n-one.Int;
209+
say $!.message if $!; # OUTPUT: «Cannot convert 0+1i to Int: imaginary part not zero␤»
180210
181-
Or
211+
Note that if the value cannot be coerced to C<Int>, an exception will
212+
be thrown.
182213
183-
enum Numbers ( cool => '42', almost-pi => '3' );
184-
say cool.Int; # OUTPUT: «42␤»
185-
say almost-pi.Int; # OUTPUT: «3␤»
214+
=head2 method Real
186215
187-
Note that if the value cannot be coerced to C<Int>, an exception will
216+
Defined as:
217+
218+
multi method Real(::?CLASS:D:)
219+
220+
Takes a value of an enum and returns it after coercion to C<Real>:
221+
222+
enum Numbers ( cool => '42', almost-pi => '3.14', sqrt-n-one => 'i' );
223+
say cool.Real; # OUTPUT: «42␤»
224+
say almost-pi.Real; # OUTPUT: «3.14␤»
225+
try say sqrt-n-one.Real;
226+
say $!.message if $!; # OUTPUT: «Cannot convert 0+1i to Real: imaginary part not zero␤»
227+
228+
Note that if the value cannot be coerced to C<Real>, an exception will
188229
be thrown.
189230
190231
=head2 method C<===>
@@ -195,7 +236,7 @@ Defined as
195236
196237
Equality of C<Enumeration> symbols:
197238
198-
=for code :preamble< enum Norse-gods <Þor Oðin Freija>;>
239+
=for code :preamble«enum Norse-gods <Þor Oðin Freija>;»
199240
say Norse-gods.pick() === Freija for ^3; # OUTPUT: «False␤False␤True␤»
200241
201242

0 commit comments

Comments
 (0)