Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some situations may require a fresh empty buffer. For example, if one want to define a function that append padded hexadecimal numbers, the use of a mere `justifyRight` requires the input `Buffer` to be empty. We introduce `newEmptyBuffer` to solve this issue. It has the caveat to require an existing `Buffer`, because we need to to know if the array is pinned or not. Working example for padded hexadecimal numbers: -- | Convenient function to append padded hex infixl 6 |>&& (|>&&) ∷ (Integral a, FiniteBits a) ⇒ Buffer ⊸ (Word, a) → Buffer b |>&& (w, n) = case newEmptyBuffer b of (# b', empty #) → (b' |># "0x"#) >< justifyRight w '0' (empty |>& n) -- Example runBuffer \b → (b |># "Foo "#) |>&& (4, 0xf ∷ Word) |># "; "# |>&& (4, 0xabc ∷ Word) -- "Foo 0x000f; 0x0abc"
- Loading branch information