Skip to content

Instantly share code, notes, and snippets.

@dminuoso
Created October 4, 2022 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/a49bd924e96c26fbd1d2869336bc6fc9 to your computer and use it in GitHub Desktop.
Save dminuoso/a49bd924e96c26fbd1d2869336bc6fc9 to your computer and use it in GitHub Desktop.
pprMac :: Mac -> T.Text
pprMac mac = let (w1, w2, w3, w4, w5, w6) = macToWord8s mac
in T.pack . fromDList $
showHex w1
<> dlistSingleton ':'
<> showHex w2
<> dlistSingleton ':'
<> showHex w3
<> dlistSingleton ':'
<> showHex w4
<> dlistSingleton ':'
<> showHex w5
<> dlistSingleton ':'
<> showHex 6
where
{-# INLINE showHex #-}
showHex :: Word8 -> DList Char
showHex w = dlistSingleton (intToDigit (fromIntegral (w `unsafeShiftR` 4)))
<> dlistSingleton (intToDigit (fromIntegral (w .&. 0xf)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment