Checks whether the slice can be interpreted as the decimal representation of a natural number.
A slice can be interpreted as a decimal natural number if it is not empty and all the characters in
it are digits. Underscores (_) are allowed as digit separators for readability, but cannot appear
at the start, at the end, or consecutively.
Use toNat? or
toNat! to convert such a slice to a natural number.
Examples:
"".toSlice.isNat = false"0".toSlice.isNat = true"5".toSlice.isNat = true"05".toSlice.isNat = true"587".toSlice.isNat = true"1_000".toSlice.isNat = true"100_000_000".toSlice.isNat = true"-587".toSlice.isNat = false" 5".toSlice.isNat = false"2+3".toSlice.isNat = false"0xff".toSlice.isNat = false"_123".toSlice.isNat = false"123_".toSlice.isNat = false"12__34".toSlice.isNat = false
Equations
- One or more equations did not get rendered due to their size.
Instances For
Interprets a slice as the decimal representation of a natural number, returning it. Returns
none if the slice does not contain a decimal natural number.
A slice can be interpreted as a decimal natural number if it is not empty and all the characters in
it are digits. Underscores (_) are allowed as digit separators and are ignored during parsing.
Use isNat to check whether toNat? would return some.
toNat! is an alternative that panics instead of
returning none when the slice is not a natural number.
Examples:
"".toSlice.toNat? = none"0".toSlice.toNat? = some 0"5".toSlice.toNat? = some 5"587".toSlice.toNat? = some 587"1_000".toSlice.toNat? = some 1000"100_000_000".toSlice.toNat? = some 100000000"-587".toSlice.toNat? = none" 5".toSlice.toNat? = none"2+3".toSlice.toNat? = none"0xff".toSlice.toNat? = none
Equations
Instances For
Interprets a slice as the decimal representation of a natural number, returning it. Panics if the slice does not contain a decimal natural number.
A slice can be interpreted as a decimal natural number if it is not empty and all the characters in
it are digits. Underscores (_) are allowed as digit separators and are ignored during parsing.
Use isNat to check whether toNat! would return a value. toNat? is a safer
alternative that returns none instead of panicking when the slice is not a natural number.
Examples:
Equations
- One or more equations did not get rendered due to their size.
Instances For
Checks whether the slice can be interpreted as the decimal representation of an integer.
A slice can be interpreted as a decimal integer if it only consists of at least one decimal digit
and optionally - in front. Underscores (_) are allowed as digit separators for
readability, but cannot appear at the start, directly after the -, at the end, or
consecutively. Leading + characters are not allowed.
Use String.Slice.toInt? or String.Slice.toInt! to convert such a slice to an integer.
Examples:
"".toSlice.isInt = false"-".toSlice.isInt = false"0".toSlice.isInt = true"-0".toSlice.isInt = true"5".toSlice.isInt = true"587".toSlice.isInt = true"-587".toSlice.isInt = true"+587".toSlice.isInt = false" 5".toSlice.isInt = false"2-3".toSlice.isInt = false"0xff".toSlice.isInt = false"-0_1".toSlice.isInt = true"-_1".toSlice.isInt = false
Instances For
Interprets a slice as the decimal representation of an integer, returning it. Returns none if
the slice does not contain a decimal integer.
A slice can be interpreted as a decimal integer if it only consists of at least one decimal digit
and optionally - in front. Underscores (_) are allowed as digit separators for
readability, but cannot appear at the start, directly after the -, at the end, or
consecutively. Leading + characters are not allowed.
Use Slice.isInt to check whether Slice.toInt? would return some.
Slice.toInt! is an alternative that panics instead of
returning none when the slice is not an integer.
Examples:
"".toSlice.toInt? = none"-".toSlice.toInt? = none"0".toSlice.toInt? = some 0"5".toSlice.toInt? = some 5"-5".toSlice.toInt? = some (-5)"587".toSlice.toInt? = some 587"-587".toSlice.toInt? = some (-587)" 5".toSlice.toInt? = none"2-3".toSlice.toInt? = none"0xff".toSlice.toInt? = none"-0_1".toSlice.toInt? = some (-1)"-_1".toSlice.toInt? = none
Equations
- s.toInt? = match s.dropPrefix? '-' with | some rest => Option.map Int.negOfNat rest.toNat? | none => Option.map Int.ofNat s.toNat?
Instances For
Interprets a slice as the decimal representation of an integer, returning it. Panics if the slice does not contain a decimal integer.
A slice can be interpreted as a decimal integer if it only consists of at least one decimal digit
and optionally - in front. Underscores (_) are allowed as digit separators for
readability, but cannot appear at the start, directly after the -, at the end, or
consecutively. Leading + characters are not allowed.
Use Slice.isInt to check whether Slice.toInt! would return a value.
Slice.toInt? is a safer alternative that returns none instead of panicking when the
slice is not an integer.
Examples: