Documentation

Init.Data.String.Slice.Numeric

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:

    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

        Equations
        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:

          Equations
          Instances For
            @[inline]

            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:

            Equations
            Instances For