Skip to content

Commit 819be1a

Browse files
committed
Document the val() from allomorphs.pm
Covers #418
1 parent b02c2f0 commit 819be1a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

doc/Type/Str.pod

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,26 @@ Form KD / Compatibility Decomposed).
895895
896896
Returns C<True> if the string is L<the same as|eq> C<$other>.
897897
898+
=head2 sub val
899+
900+
=comment
901+
seems like the best place to document this
902+
903+
multi sub val(Str:D $MAYBEVAL, :$val-or-fail)
904+
905+
Given a C<Str> that may be parseable as a numeric value, it will
906+
attempt to construct the appropriate L<allomorph|/language/glossary#Allomorph>,
907+
returning one of L<IntStr|/type/IntStr>, L<NumStr|/type/NumStr>, L<RatStr|/type/RatStr>
908+
or L<ComplexStr|/type/ComplexStr> or a plain C<Str> if a numeric value cannot
909+
be parsed. If the C<:val-or-fail> adverb is provided it will return an
910+
L<X::Str::Numeric|/type/X/Str/Numeric> rather than the original string if it
911+
cannot parse the string as a number.
912+
913+
say val("42").WHAT; # (IntStr)
914+
say val("42e0").WHAT; # (NumStr)
915+
say val("42.0").WHAT; # (RatStr)
916+
say val("42+0i").WHAT; # (ComplexStr)
917+
898918
=end pod
899919

900920
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)