si-bytes-0.1: Byte with type-level units (e.g. B, KB, MB, ...).
Safe HaskellNone
LanguageHaskell2010

Data.Bytes.Formatting

Description

Provides high level formatters for different byte types. This module contains the functions and types for typical usage. Additional functionality (e.g. optics, type classes/families for defining custom formatters) can be found in:

Since: 0.1

Synopsis

High-level functions

formatSized Source #

Arguments

:: (Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a), RawNumeric a, Sized a) 
=> BaseFormatter (Raw a)

Formatter to use on the underlying value i.e. IntegralFormatter or FloatingFormatter.

-> SizedFormatter

Formatter to use on the size units.

-> a

Value to be formatted.

-> Text

Result.

Formats a value with Size units. Can be used with all byte types in this package.

Examples

Expand
>>> import Data.Default (Default (..))
>>> import Data.Bytes (Bytes (..), Size (..), hideSize)
>>> let bf1 = MkIntegralFormatter
>>> let b1 = MkBytes @M @Int 7
>>> formatSized bf1 def b1
"7 mb"
>>> formatSized bf1 sizedFormatterUnix b1
"7M"
>>> let bf2 = MkFloatingFormatter (Just 2)
>>> let b2 = hideSize $ MkBytes @G @Float 20.248
>>> formatSized bf2 sizedFormatterVerbose b2
"20.25 gigabytes"

Since: 0.1

formatSizedDirected Source #

Arguments

:: (Directed a, Formatter (BaseFormatter (Raw a)), PrintfArg (Raw a), RawNumeric a, Sized a) 
=> BaseFormatter (Raw a)

Formatter to use on the underlying value i.e. IntegralFormatter or FloatingFormatter.

-> SizedFormatter

Formatter to use on the size units.

-> DirectedFormatter

Formatter to use on the direction units.

-> a

Value to be formatted.

-> Text

Result.

Formats a value with Size and Direction units. Can only be used when both units are present.

Examples

Expand
>>> import Data.Default (Default (..))
>>> import Data.Bytes.Network (Direction (..), NetBytes (..), Size (..))
>>> import Data.Bytes.Size (Sized (..))
>>> let bf1 = MkIntegralFormatter
>>> let b1 = MkNetBytesP @Up @M @Int 7
>>> formatSizedDirected bf1 def def b1
"7 mb up"
>>> formatSizedDirected bf1 sizedFormatterUnix directedFormatterUnix b1
"7M U"
>>> let bf2 = MkFloatingFormatter (Just 2)
>>> let b2 = hideSize $ MkNetBytesP @Down @G @Float 20.248
>>> formatSizedDirected bf2 sizedFormatterVerbose directedFormatterVerbose b2
"20.25 gigabytes down"

Since: 0.1

Types

Base

data CaseFormat Source #

Case formatting.

Since: 0.1

Constructors

CaseFormatLower

Since: 0.1

CaseFormatTitle

Since: 0.1

CaseFormatUpper

Since: 0.1

Instances

Instances details
Show CaseFormat Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Base

Eq CaseFormat Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Base

data IntegralFormatter Source #

Formatter for integral types.

Since: 0.1

Constructors

MkIntegralFormatter 

Instances

Instances details
Formatter IntegralFormatter Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Base

newtype FloatingFormatter Source #

Formatter for floating types. Takes an optional param for rounding digits.

Since: 0.1

Instances

Instances details
Formatter FloatingFormatter Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Base

Size

data SizeFormat Source #

Determines how to format the size units.

Examples

Expand
>>> def @SizeFormat
SizeFormatMedium

Since: 0.1

Constructors

SizeFormatShort

Since: 0.1

SizeFormatMedium

Since: 0.1

SizeFormatLong

Since: 0.1

Instances

Instances details
Default SizeFormat Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Size

Show SizeFormat Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Size

Eq SizeFormat Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Size

data SizedFormatter Source #

Formatting size units.

Examples

Expand
>>> def @SizedFormatter
MkSizedFormatter {caseFormat = CaseFormatLower, leadingSpace = True, sizeFormat = SizeFormatMedium}

Since: 0.1

Instances

Instances details
Default SizedFormatter Source # 
Instance details

Defined in Data.Bytes.Formatting.Size

Show SizedFormatter Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Size

Eq SizedFormatter Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Size

Formatter SizedFormatter Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Size

(k ~ A_Lens, a ~ CaseFormat, b ~ CaseFormat) => LabelOptic "caseFormat" k SizedFormatter SizedFormatter a b Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Size

(k ~ A_Lens, a ~ Bool, b ~ Bool) => LabelOptic "leadingSpace" k SizedFormatter SizedFormatter a b Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Size

(k ~ A_Lens, a ~ SizeFormat, b ~ SizeFormat) => LabelOptic "sizeFormat" k SizedFormatter SizedFormatter a b Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Size

sizedFormatterUnix :: SizedFormatter Source #

Unix-style formatter:

  • Upper case.
  • No space between value and unit.
  • Single letter unit.

For example: 7G.

Since: 0.1

sizedFormatterNatural :: SizedFormatter Source #

Natural-style formatter:

  • Lower case.
  • Space between value and unit.
  • Two letter units.

For example: 7 gb.

Since: 0.1

sizedFormatterVerbose :: SizedFormatter Source #

Verbose formatter:

  • Lower case.
  • Space between value and unit.
  • Full spelling.

For example: 7 gigabytes.

Since: 0.1

Direction

data DirectionFormat Source #

Determines how to format the direction units.

Examples

Expand
>>> def @DirectionFormat
DirectionFormatLong

Since: 0.1

Constructors

DirectionFormatShort

Since: 0.1

DirectionFormatLong

Since: 0.1

data DirectedFormatter Source #

Formats bytes over floating types.

Examples

Expand
>>> def @DirectedFormatter
MkDirectedFormatter {caseFormat = CaseFormatLower, directionFormat = DirectionFormatLong}

Since: 0.1

directedFormatterUnix :: DirectedFormatter Source #

"unix"-style formatter:

  • Upper case.
  • Short spelling.

For example: 7 U.

Since: 0.1

directedFormatterVerbose :: DirectedFormatter Source #

Verbose formatter:

  • Lower case.
  • Full spelling.

For example: 7 down.

Since: 0.1

Reexports

class Default a where Source #

A class for types with a default value.

Minimal complete definition

Nothing

Methods

def :: a Source #

The default value for this type.

default def :: (Generic a, GDefault (Rep a)) => a Source #

Instances

Instances details
Default All 
Instance details

Defined in Data.Default.Class

Methods

def :: All Source #

Default Any 
Instance details

Defined in Data.Default.Class

Methods

def :: Any Source #

Default CClock 
Instance details

Defined in Data.Default.Class

Methods

def :: CClock Source #

Default CDouble 
Instance details

Defined in Data.Default.Class

Methods

def :: CDouble Source #

Default CFloat 
Instance details

Defined in Data.Default.Class

Methods

def :: CFloat Source #

Default CInt 
Instance details

Defined in Data.Default.Class

Methods

def :: CInt Source #

Default CIntMax 
Instance details

Defined in Data.Default.Class

Methods

def :: CIntMax Source #

Default CIntPtr 
Instance details

Defined in Data.Default.Class

Methods

def :: CIntPtr Source #

Default CLLong 
Instance details

Defined in Data.Default.Class

Methods

def :: CLLong Source #

Default CLong 
Instance details

Defined in Data.Default.Class

Methods

def :: CLong Source #

Default CPtrdiff 
Instance details

Defined in Data.Default.Class

Methods

def :: CPtrdiff Source #

Default CSUSeconds 
Instance details

Defined in Data.Default.Class

Default CShort 
Instance details

Defined in Data.Default.Class

Methods

def :: CShort Source #

Default CSigAtomic 
Instance details

Defined in Data.Default.Class

Default CSize 
Instance details

Defined in Data.Default.Class

Methods

def :: CSize Source #

Default CTime 
Instance details

Defined in Data.Default.Class

Methods

def :: CTime Source #

Default CUInt 
Instance details

Defined in Data.Default.Class

Methods

def :: CUInt Source #

Default CUIntMax 
Instance details

Defined in Data.Default.Class

Methods

def :: CUIntMax Source #

Default CUIntPtr 
Instance details

Defined in Data.Default.Class

Methods

def :: CUIntPtr Source #

Default CULLong 
Instance details

Defined in Data.Default.Class

Methods

def :: CULLong Source #

Default CULong 
Instance details

Defined in Data.Default.Class

Methods

def :: CULong Source #

Default CUSeconds 
Instance details

Defined in Data.Default.Class

Methods

def :: CUSeconds Source #

Default CUShort 
Instance details

Defined in Data.Default.Class

Methods

def :: CUShort Source #

Default Int16 
Instance details

Defined in Data.Default.Class

Methods

def :: Int16 Source #

Default Int32 
Instance details

Defined in Data.Default.Class

Methods

def :: Int32 Source #

Default Int64 
Instance details

Defined in Data.Default.Class

Methods

def :: Int64 Source #

Default Int8 
Instance details

Defined in Data.Default.Class

Methods

def :: Int8 Source #

Default Word16 
Instance details

Defined in Data.Default.Class

Methods

def :: Word16 Source #

Default Word32 
Instance details

Defined in Data.Default.Class

Methods

def :: Word32 Source #

Default Word64 
Instance details

Defined in Data.Default.Class

Methods

def :: Word64 Source #

Default Word8 
Instance details

Defined in Data.Default.Class

Methods

def :: Word8 Source #

Default Ordering 
Instance details

Defined in Data.Default.Class

Methods

def :: Ordering Source #

Default DirectedFormatter Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Direction

Default DirectionFormat Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Direction

Default SizeFormat Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Formatting.Size

Default SizedFormatter Source # 
Instance details

Defined in Data.Bytes.Formatting.Size

Default Integer 
Instance details

Defined in Data.Default.Class

Methods

def :: Integer Source #

Default () 
Instance details

Defined in Data.Default.Class

Methods

def :: () Source #

Default Double 
Instance details

Defined in Data.Default.Class

Methods

def :: Double Source #

Default Float 
Instance details

Defined in Data.Default.Class

Methods

def :: Float Source #

Default Int 
Instance details

Defined in Data.Default.Class

Methods

def :: Int Source #

Default Word 
Instance details

Defined in Data.Default.Class

Methods

def :: Word Source #

(Default a, RealFloat a) => Default (Complex a) 
Instance details

Defined in Data.Default.Class

Methods

def :: Complex a Source #

Default (First a) 
Instance details

Defined in Data.Default.Class

Methods

def :: First a Source #

Default (Last a) 
Instance details

Defined in Data.Default.Class

Methods

def :: Last a Source #

Default a => Default (Dual a) 
Instance details

Defined in Data.Default.Class

Methods

def :: Dual a Source #

Default (Endo a) 
Instance details

Defined in Data.Default.Class

Methods

def :: Endo a Source #

Num a => Default (Product a) 
Instance details

Defined in Data.Default.Class

Methods

def :: Product a Source #

Num a => Default (Sum a) 
Instance details

Defined in Data.Default.Class

Methods

def :: Sum a Source #

Integral a => Default (Ratio a) 
Instance details

Defined in Data.Default.Class

Methods

def :: Ratio a Source #

Default a => Default (IO a) 
Instance details

Defined in Data.Default.Class

Methods

def :: IO a Source #

Default (Maybe a) 
Instance details

Defined in Data.Default.Class

Methods

def :: Maybe a Source #

Default [a] 
Instance details

Defined in Data.Default.Class

Methods

def :: [a] Source #

(Default a, Default b) => Default (a, b) 
Instance details

Defined in Data.Default.Class

Methods

def :: (a, b) Source #

Default r => Default (e -> r) 
Instance details

Defined in Data.Default.Class

Methods

def :: e -> r Source #

(Default a, Default b, Default c) => Default (a, b, c) 
Instance details

Defined in Data.Default.Class

Methods

def :: (a, b, c) Source #

(Default a, Default b, Default c, Default d) => Default (a, b, c, d) 
Instance details

Defined in Data.Default.Class

Methods

def :: (a, b, c, d) Source #

(Default a, Default b, Default c, Default d, Default e) => Default (a, b, c, d, e) 
Instance details

Defined in Data.Default.Class

Methods

def :: (a, b, c, d, e) Source #

(Default a, Default b, Default c, Default d, Default e, Default f) => Default (a, b, c, d, e, f) 
Instance details

Defined in Data.Default.Class

Methods

def :: (a, b, c, d, e, f) Source #

(Default a, Default b, Default c, Default d, Default e, Default f, Default g) => Default (a, b, c, d, e, f, g) 
Instance details

Defined in Data.Default.Class

Methods

def :: (a, b, c, d, e, f, g) Source #