File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -895,6 +895,26 @@ Form KD / Compatibility Decomposed).
895
895
896
896
Returns C < True > if the string is L < the same as|eq > C < $other > .
897
897
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
+
898
918
= end pod
899
919
900
920
# vim: expandtab shiftwidth=4 ft=perl6
You can’t perform that action at this time.
0 commit comments