haskell / haskell/text

Padded decimal and hexadecimal text builders

Open
#163 3 comments 0 reactions 0 assignees View on GitHub
feature request
Dominant language
Haskell
Stars
421
Forks
163
PR merge metrics
No merged PRs in 30d

Description

In `Data.Text.Lazy.Builder.Int`, the functions `decimal` and `hexadecimal` are available. Sometimes, I need to zero pad my decimal and hexadecimal representations to a certain length. I propose adding the following two functions to this module:

```
paddedDecimal :: Integral a => Int -> a -> Builder
paddedHexadecimal :: Integral a => Int -> a -> Builder
```

The behaviors of these would be:
- The padding occurs on the left.
- The padding adds zeroes until that cause the builder to be of the desired length.
- The padding happens after the minus sign in the event that the number is negative.

Examples of expected behavior:

```
> paddedDecimal 3 5
005
> paddedDecimal 6 (-103)
-000103
> paddedDecimal 2 1039
1039
> paddedDecimal (-5) 1
1
```

If this would be a welcome addition, I am already familiar with the integral text builder code, and I would be happy to add these functions. The only place where I am uncertain of how to proceed would be writing a performant specialization for `Integer`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.