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

Data.Bytes.Network.Internal

Description

Internal module for Data.Network.NetBytes. The primary difference is this module exposes some underlying details i.e. singleton witnesses. These are hidden by default as they complicate the API.

Since: 0.1

Synopsis

Network Bytes

newtype NetBytes (d :: Direction) (s :: Size) n Source #

Wrapper around the Bytes type that adds the Direction tag.

Examples

Expand
>>> MkNetBytesP @Up @M 1000
MkNetBytes (MkBytes 1000)

Since: 0.1

Constructors

MkNetBytes (Bytes s n) 

Bundled Patterns

pattern MkNetBytesP :: forall d s n. n -> NetBytes d s n

Pattern for de/constructing NetBytes.

Since: 0.1

Instances

Instances details
HasField "unNetBytes" (NetBytes d s n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

getField :: NetBytes d s n -> n #

(k ~ An_Iso, a ~ n, b ~ n) => LabelOptic "unNetBytes" k (NetBytes d s n) (NetBytes d s n) a b Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

labelOptic :: Optic k NoIx (NetBytes d s n) (NetBytes d s n) a b Source #

Applicative (NetBytes d s) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

pure :: a -> NetBytes d s a #

(<*>) :: NetBytes d s (a -> b) -> NetBytes d s a -> NetBytes d s b #

liftA2 :: (a -> b -> c) -> NetBytes d s a -> NetBytes d s b -> NetBytes d s c #

(*>) :: NetBytes d s a -> NetBytes d s b -> NetBytes d s b #

(<*) :: NetBytes d s a -> NetBytes d s b -> NetBytes d s a #

Functor (NetBytes d s) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

fmap :: (a -> b) -> NetBytes d s a -> NetBytes d s b #

(<$) :: a -> NetBytes d s b -> NetBytes d s a #

Monad (NetBytes d s) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(>>=) :: NetBytes d s a -> (a -> NetBytes d s b) -> NetBytes d s b #

(>>) :: NetBytes d s a -> NetBytes d s b -> NetBytes d s b #

return :: a -> NetBytes d s a #

Foldable (NetBytes d s) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

fold :: Monoid m => NetBytes d s m -> m #

foldMap :: Monoid m => (a -> m) -> NetBytes d s a -> m #

foldMap' :: Monoid m => (a -> m) -> NetBytes d s a -> m #

foldr :: (a -> b -> b) -> b -> NetBytes d s a -> b #

foldr' :: (a -> b -> b) -> b -> NetBytes d s a -> b #

foldl :: (b -> a -> b) -> b -> NetBytes d s a -> b #

foldl' :: (b -> a -> b) -> b -> NetBytes d s a -> b #

foldr1 :: (a -> a -> a) -> NetBytes d s a -> a #

foldl1 :: (a -> a -> a) -> NetBytes d s a -> a #

toList :: NetBytes d s a -> [a] #

null :: NetBytes d s a -> Bool #

length :: NetBytes d s a -> Int #

elem :: Eq a => a -> NetBytes d s a -> Bool #

maximum :: Ord a => NetBytes d s a -> a #

minimum :: Ord a => NetBytes d s a -> a #

sum :: Num a => NetBytes d s a -> a #

product :: Num a => NetBytes d s a -> a #

Traversable (NetBytes d s) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

traverse :: Applicative f => (a -> f b) -> NetBytes d s a -> f (NetBytes d s b) #

sequenceA :: Applicative f => NetBytes d s (f a) -> f (NetBytes d s a) #

mapM :: Monad m => (a -> m b) -> NetBytes d s a -> m (NetBytes d s b) #

sequence :: Monad m => NetBytes d s (m a) -> m (NetBytes d s a) #

AGroup n => AGroup (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.-.) :: NetBytes d s n -> NetBytes d s n -> NetBytes d s n Source #

AMonoid n => AMonoid (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

zero :: NetBytes d s n Source #

ASemigroup n => ASemigroup (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.+.) :: NetBytes d s n -> NetBytes d s n -> NetBytes d s n Source #

Normed n => Normed (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

norm :: NetBytes d s n -> NetBytes d s n Source #

FromInteger n => FromInteger (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

afromInteger :: Integer -> NetBytes d s n Source #

FromRational n => FromRational (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

AnyLowerBounded n => AnyLowerBounded (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

AnyUpperBounded n => AnyUpperBounded (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

LowerBounded n => LowerBounded (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

lowerBound :: NetBytes d s n Source #

LowerBoundless (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

UpperBounded n => UpperBounded (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

upperBound :: NetBytes d s n Source #

UpperBoundless (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

NFData n => NFData (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

rnf :: NetBytes d s n -> () #

Generic (NetBytes d s n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type Rep (NetBytes d s n)

Since: si-bytes-0.1

Instance details

Defined in Data.Bytes.Network.Internal

type Rep (NetBytes d s n) = D1 ('MetaData "NetBytes" "Data.Bytes.Network.Internal" "si-bytes-0.1-inplace" 'True) (C1 ('MetaCons "MkNetBytes" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Bytes s n))))

Methods

from :: NetBytes d s n -> Rep (NetBytes d s n) x #

to :: Rep (NetBytes d s n) x -> NetBytes d s n #

Show n => Show (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

showsPrec :: Int -> NetBytes d s n -> ShowS #

show :: NetBytes d s n -> String #

showList :: [NetBytes d s n] -> ShowS #

Eq n => Eq (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(==) :: NetBytes d s n -> NetBytes d s n -> Bool #

(/=) :: NetBytes d s n -> NetBytes d s n -> Bool #

Ord n => Ord (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

compare :: NetBytes d s n -> NetBytes d s n -> Ordering #

(<) :: NetBytes d s n -> NetBytes d s n -> Bool #

(<=) :: NetBytes d s n -> NetBytes d s n -> Bool #

(>) :: NetBytes d s n -> NetBytes d s n -> Bool #

(>=) :: NetBytes d s n -> NetBytes d s n -> Bool #

max :: NetBytes d s n -> NetBytes d s n -> NetBytes d s n #

min :: NetBytes d s n -> NetBytes d s n -> NetBytes d s n #

Hashable n => Hashable (NetBytes d s n) Source #

@since 0.1,

Instance details

Defined in Data.Bytes.Network.Internal

Methods

hashWithSalt :: Int -> NetBytes d s n -> Int Source #

hash :: NetBytes d s n -> Int Source #

(FromInteger n, MGroup n, SingSize s) => Conversion (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

convert_ :: forall (t :: Size). SingSize t => NetBytes d s n -> Converted t (NetBytes d s n) Source #

(FromInteger n, MGroup n, Normed n, Ord n, SingSize s) => Normalize (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type Norm (NetBytes d s n) 
Instance details

Defined in Data.Bytes.Network.Internal

type Norm (NetBytes d s n) = SomeNetSize d n

Methods

normalize :: NetBytes d s n -> Norm (NetBytes d s n) Source #

Read n => Parser (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

parser :: Parsec Void Text (NetBytes d s n) Source #

RawNumeric (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type Raw (NetBytes d s n) 
Instance details

Defined in Data.Bytes.Network.Internal

type Raw (NetBytes d s n) = n

Methods

toRaw :: NetBytes d s n -> Raw (NetBytes d s n) Source #

SingDirection d => Directed (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideDirection (NetBytes d s n) 
Instance details

Defined in Data.Bytes.Network.Internal

type HideDirection (NetBytes d s n) = SomeNetDir s n
SingSize s => Sized (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideSize (NetBytes d s n) 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (NetBytes d s n) = SomeNetSize d n

Methods

sizeOf :: NetBytes d s n -> Size Source #

hideSize :: NetBytes d s n -> HideSize (NetBytes d s n) Source #

MSemigroup n => MSemiSpace (NetBytes d s n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.*) :: NetBytes d s n -> n -> NetBytes d s n Source #

MGroup n => MSpace (NetBytes d s n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.%) :: NetBytes d s n -> n -> NetBytes d s n Source #

Ring n => Module (NetBytes d s n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Semiring n => Semimodule (NetBytes d s n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Semifield n => SemivectorSpace (NetBytes d s n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Field n => VectorSpace (NetBytes d s n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

type Converted t (NetBytes d s n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Converted t (NetBytes d s n) = NetBytes d t n
type Rep (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

type Rep (NetBytes d s n) = D1 ('MetaData "NetBytes" "Data.Bytes.Network.Internal" "si-bytes-0.1-inplace" 'True) (C1 ('MetaCons "MkNetBytes" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Bytes s n))))
type Norm (NetBytes d s n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Norm (NetBytes d s n) = SomeNetSize d n
type Raw (NetBytes d s n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Raw (NetBytes d s n) = n
type HideDirection (NetBytes d s n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type HideDirection (NetBytes d s n) = SomeNetDir s n
type HideSize (NetBytes d s n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (NetBytes d s n) = SomeNetSize d n

_MkNetBytes :: forall (s :: Size) (d :: Direction) n. Iso' (NetBytes d s n) (Bytes s n) Source #

Iso' between NetBytes and underlying Bytes.

Examples

Expand
>>> import Optics.Core (review, view)
>>> review _MkNetBytes (MkBytes @K @Int 70)
MkNetBytes (MkBytes 70)
>>> view _MkNetBytes (MkNetBytes $ MkBytes @K @Int 70)
MkBytes 70

Since: 0.1

netToSSize :: forall (s :: Size) (d :: Direction) n. SingSize s => NetBytes d s n -> SSize s Source #

Retrieves the SingSize witness. Can be used to recover the Size.

>>> netToSSize (MkNetBytesP @Down @K @Int 7)
SK

Since: 0.1

netToSDirection :: forall (d :: Direction) (s :: Size) n. SingDirection d => NetBytes d s n -> SDirection d Source #

Retrieves the SDirection witness. Can be used to recover the Direction.

>>> netToSDirection (MkNetBytesP @Up @K @Int 7)
SUp

Since: 0.1

Unknown Size

data SomeNetSize (d :: Direction) n where Source #

Wrapper for NetBytes, existentially quantifying the size. This is useful when a function does not know a priori what size it should return e.g.

>>> :{
  getUpTraffic :: IO (SomeNetSize Up Float)
  getUpTraffic = do
    -- getUpTrafficRaw :: IO (Float, String)
    (bytes, units) <- getUpTrafficRaw
    pure $ case units of
      "B" -> hideSize $ MkNetBytesP @Up @B bytes
      "K" -> hideSize $ MkNetBytesP @Up @K bytes
      _ -> error "todo"
:}

We define an equivalence relation on SomeNetSize that takes units into account. For instance,

>>> hideSize (MkNetBytesP @Up @K 1000) == hideSize (MkNetBytesP @Up @M 1)
True

Because we expose the underlying NetBytes in several ways (e.g. Show, the SSize witness), this is technically unlawful for equality as it breaks the extensionality law:

\[ x = y \implies f(x) = f(y). \]

Since: 0.1

Constructors

MkSomeNetSize :: forall (s :: Size) (d :: Direction) n. SSize s -> NetBytes d s n -> SomeNetSize d n

Since: 0.1

Instances

Instances details
HasField "unSomeNetSize" (SomeNetSize d n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

getField :: SomeNetSize d n -> n #

(k ~ A_Getter, a ~ n, b ~ n) => LabelOptic "unSomeNetSize" k (SomeNetSize d n) (SomeNetSize d n) a b Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

labelOptic :: Optic k NoIx (SomeNetSize d n) (SomeNetSize d n) a b Source #

Functor (SomeNetSize d) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

fmap :: (a -> b) -> SomeNetSize d a -> SomeNetSize d b #

(<$) :: a -> SomeNetSize d b -> SomeNetSize d a #

Foldable (SomeNetSize d) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

fold :: Monoid m => SomeNetSize d m -> m #

foldMap :: Monoid m => (a -> m) -> SomeNetSize d a -> m #

foldMap' :: Monoid m => (a -> m) -> SomeNetSize d a -> m #

foldr :: (a -> b -> b) -> b -> SomeNetSize d a -> b #

foldr' :: (a -> b -> b) -> b -> SomeNetSize d a -> b #

foldl :: (b -> a -> b) -> b -> SomeNetSize d a -> b #

foldl' :: (b -> a -> b) -> b -> SomeNetSize d a -> b #

foldr1 :: (a -> a -> a) -> SomeNetSize d a -> a #

foldl1 :: (a -> a -> a) -> SomeNetSize d a -> a #

toList :: SomeNetSize d a -> [a] #

null :: SomeNetSize d a -> Bool #

length :: SomeNetSize d a -> Int #

elem :: Eq a => a -> SomeNetSize d a -> Bool #

maximum :: Ord a => SomeNetSize d a -> a #

minimum :: Ord a => SomeNetSize d a -> a #

sum :: Num a => SomeNetSize d a -> a #

product :: Num a => SomeNetSize d a -> a #

Traversable (SomeNetSize d) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

traverse :: Applicative f => (a -> f b) -> SomeNetSize d a -> f (SomeNetSize d b) #

sequenceA :: Applicative f => SomeNetSize d (f a) -> f (SomeNetSize d a) #

mapM :: Monad m => (a -> m b) -> SomeNetSize d a -> m (SomeNetSize d b) #

sequence :: Monad m => SomeNetSize d (m a) -> m (SomeNetSize d a) #

(Field n, FromInteger n) => AGroup (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.-.) :: SomeNetSize d n -> SomeNetSize d n -> SomeNetSize d n Source #

(FromInteger n, Semifield n) => AMonoid (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

zero :: SomeNetSize d n Source #

(ASemigroup n, FromInteger n, MGroup n) => ASemigroup (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.+.) :: SomeNetSize d n -> SomeNetSize d n -> SomeNetSize d n Source #

FromInteger n => FromInteger (SomeNetSize d n) Source #

Fixed size B.

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

FromRational n => FromRational (SomeNetSize d n) Source #

Fixed size B.

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

NFData n => NFData (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

rnf :: SomeNetSize d n -> () #

Show n => Show (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

showsPrec :: Int -> SomeNetSize d n -> ShowS #

show :: SomeNetSize d n -> String #

showList :: [SomeNetSize d n] -> ShowS #

(Eq n, FromInteger n, MGroup n) => Eq (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(==) :: SomeNetSize d n -> SomeNetSize d n -> Bool #

(/=) :: SomeNetSize d n -> SomeNetSize d n -> Bool #

(FromInteger n, MGroup n, Ord n) => Ord (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

compare :: SomeNetSize d n -> SomeNetSize d n -> Ordering #

(<) :: SomeNetSize d n -> SomeNetSize d n -> Bool #

(<=) :: SomeNetSize d n -> SomeNetSize d n -> Bool #

(>) :: SomeNetSize d n -> SomeNetSize d n -> Bool #

(>=) :: SomeNetSize d n -> SomeNetSize d n -> Bool #

max :: SomeNetSize d n -> SomeNetSize d n -> SomeNetSize d n #

min :: SomeNetSize d n -> SomeNetSize d n -> SomeNetSize d n #

(FromInteger n, Hashable n, MGroup n) => Hashable (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

(FromInteger n, MGroup n) => Conversion (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

convert_ :: forall (t :: Size). SingSize t => SomeNetSize d n -> Converted t (SomeNetSize d n) Source #

(FromInteger n, MGroup n, Normed n, Ord n) => Normalize (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type Norm (SomeNetSize d n) 
Instance details

Defined in Data.Bytes.Network.Internal

type Norm (SomeNetSize d n) = SomeNetSize d n

Methods

normalize :: SomeNetSize d n -> Norm (SomeNetSize d n) Source #

Read n => Parser (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

RawNumeric (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type Raw (SomeNetSize d n) 
Instance details

Defined in Data.Bytes.Network.Internal

type Raw (SomeNetSize d n) = n

Methods

toRaw :: SomeNetSize d n -> Raw (SomeNetSize d n) Source #

SingDirection d => Directed (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideDirection (SomeNetSize d n) 
Instance details

Defined in Data.Bytes.Network.Internal

Sized (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideSize (SomeNetSize d n) 
Instance details

Defined in Data.Bytes.Network.Internal

MGroup n => MSemiSpace (SomeNetSize d n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.*) :: SomeNetSize d n -> n -> SomeNetSize d n Source #

MGroup n => MSpace (SomeNetSize d n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.%) :: SomeNetSize d n -> n -> SomeNetSize d n Source #

(Field n, FromInteger n) => Module (SomeNetSize d n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

(FromInteger n, Semifield n) => Semimodule (SomeNetSize d n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

(FromInteger n, Semifield n) => SemivectorSpace (SomeNetSize d n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

(FromInteger n, Field n) => VectorSpace (SomeNetSize d n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

type Converted t (SomeNetSize d n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Converted t (SomeNetSize d n) = NetBytes d t n
type Norm (SomeNetSize d n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Norm (SomeNetSize d n) = SomeNetSize d n
type Raw (SomeNetSize d n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Raw (SomeNetSize d n) = n
type HideDirection (SomeNetSize d n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (SomeNetSize d n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

_MkSomeNetSize :: forall (s :: Size) (d :: Direction) n. (FromInteger n, MGroup n, SingSize s) => Iso' (SomeNetSize d n) (NetBytes d s n) Source #

Iso' between SomeNetSize and underlying NetBytes. Performs any necessary conversions when going from SomeNetSize d n -> NetBytes d s n.

Examples

Expand
>>> import Optics.Core (review, view)
>>> review _MkSomeNetSize (MkNetBytesP @Up @K @Int 70)
MkSomeNetSize SK (MkNetBytes (MkBytes 70))
>>> (view _MkSomeNetSize (hideSize $ MkNetBytesP @Up @K @Int 70)) :: NetBytes Up B Int
MkNetBytes (MkBytes 70000)

Since: 0.1

someNetSizeToSDirection :: forall (d :: Direction) n. SingDirection d => SomeNetSize d n -> SDirection d Source #

Retrieves the SingDirection witness. Can be used to recover the Direction.

Since: 0.1

Unknown Direction

data SomeNetDir (s :: Size) n where Source #

Wrapper for NetBytes, existentially quantifying the direction. This is useful when a function does not know a priori what direction it should return e.g.

>>> :{
  getMaxTraffic :: IO (SomeNetDir K Double)
  getMaxTraffic = do
    -- getMaxTraffickRaw :: IO (Double, String)
    (bytes, direction) <- getMaxTraffickRaw
    pure $ case direction of
      "down" -> hideDirection $ MkNetBytesP @Down bytes
      "up" -> hideDirection $ MkNetBytesP @Up bytes
      _ -> error "bad direction"
:}

We deliberately do not provide instances for SomeX classes that could be used to combine arbitrary SomeNetDirs (e.g. Applicative, AGroup), as that would defeat the purpose of enforcing the distinction between upload and downloaded bytes.

Equality is determined by the usual equivalence class -- that takes units into account -- and by considering the direction.

>>> let x = MkNetBytesP @Up @K 1000 :: NetBytes Up K Int
>>> let y = MkNetBytesP @Down @K 1000 :: NetBytes Down K Int
>>> hideDirection x == hideDirection x
True
>>> hideDirection x == hideDirection y
False

Notice no Ord instance is provided, as we provide no ordering for Direction.

Since: 0.1

Constructors

MkSomeNetDir :: forall (d :: Direction) (s :: Size) n. SDirection d -> NetBytes d s n -> SomeNetDir s n

Since: 0.1

Instances

Instances details
HasField "unSomeNetDir" (SomeNetDir s n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

getField :: SomeNetDir s n -> n #

(k ~ A_Getter, a ~ n, b ~ n) => LabelOptic "unSomeNetDir" k (SomeNetDir s n) (SomeNetDir s n) a b Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

labelOptic :: Optic k NoIx (SomeNetDir s n) (SomeNetDir s n) a b Source #

Functor (SomeNetDir s) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

fmap :: (a -> b) -> SomeNetDir s a -> SomeNetDir s b #

(<$) :: a -> SomeNetDir s b -> SomeNetDir s a #

Foldable (SomeNetDir s) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

fold :: Monoid m => SomeNetDir s m -> m #

foldMap :: Monoid m => (a -> m) -> SomeNetDir s a -> m #

foldMap' :: Monoid m => (a -> m) -> SomeNetDir s a -> m #

foldr :: (a -> b -> b) -> b -> SomeNetDir s a -> b #

foldr' :: (a -> b -> b) -> b -> SomeNetDir s a -> b #

foldl :: (b -> a -> b) -> b -> SomeNetDir s a -> b #

foldl' :: (b -> a -> b) -> b -> SomeNetDir s a -> b #

foldr1 :: (a -> a -> a) -> SomeNetDir s a -> a #

foldl1 :: (a -> a -> a) -> SomeNetDir s a -> a #

toList :: SomeNetDir s a -> [a] #

null :: SomeNetDir s a -> Bool #

length :: SomeNetDir s a -> Int #

elem :: Eq a => a -> SomeNetDir s a -> Bool #

maximum :: Ord a => SomeNetDir s a -> a #

minimum :: Ord a => SomeNetDir s a -> a #

sum :: Num a => SomeNetDir s a -> a #

product :: Num a => SomeNetDir s a -> a #

Traversable (SomeNetDir d) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

traverse :: Applicative f => (a -> f b) -> SomeNetDir d a -> f (SomeNetDir d b) #

sequenceA :: Applicative f => SomeNetDir d (f a) -> f (SomeNetDir d a) #

mapM :: Monad m => (a -> m b) -> SomeNetDir d a -> m (SomeNetDir d b) #

sequence :: Monad m => SomeNetDir d (m a) -> m (SomeNetDir d a) #

Normed n => Normed (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

norm :: SomeNetDir s n -> SomeNetDir s n Source #

NFData n => NFData (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

rnf :: SomeNetDir s n -> () #

Show n => Show (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

showsPrec :: Int -> SomeNetDir s n -> ShowS #

show :: SomeNetDir s n -> String #

showList :: [SomeNetDir s n] -> ShowS #

(Eq n, FromInteger n, SingSize s) => Eq (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(==) :: SomeNetDir s n -> SomeNetDir s n -> Bool #

(/=) :: SomeNetDir s n -> SomeNetDir s n -> Bool #

(FromInteger n, Hashable n, MGroup n, SingSize s) => Hashable (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

(FromInteger n, MGroup n, SingSize s) => Conversion (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

convert_ :: forall (t :: Size). SingSize t => SomeNetDir s n -> Converted t (SomeNetDir s n) Source #

(FromInteger n, MGroup n, Normed n, Ord n, SingSize s) => Normalize (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type Norm (SomeNetDir s n) 
Instance details

Defined in Data.Bytes.Network.Internal

type Norm (SomeNetDir s n) = SomeNet n

Methods

normalize :: SomeNetDir s n -> Norm (SomeNetDir s n) Source #

Read n => Parser (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

RawNumeric (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type Raw (SomeNetDir s n) 
Instance details

Defined in Data.Bytes.Network.Internal

type Raw (SomeNetDir s n) = n

Methods

toRaw :: SomeNetDir s n -> Raw (SomeNetDir s n) Source #

Directed (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideDirection (SomeNetDir s n) 
Instance details

Defined in Data.Bytes.Network.Internal

SingSize s => Sized (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideSize (SomeNetDir s n) 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (SomeNetDir s n) = SomeNet n
MSemigroup n => MSemiSpace (SomeNetDir s n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.*) :: SomeNetDir s n -> n -> SomeNetDir s n Source #

MGroup n => MSpace (SomeNetDir s n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.%) :: SomeNetDir s n -> n -> SomeNetDir s n Source #

type Converted t (SomeNetDir s n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Converted t (SomeNetDir s n) = SomeNetDir t n
type Norm (SomeNetDir s n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Norm (SomeNetDir s n) = SomeNet n
type Raw (SomeNetDir s n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Raw (SomeNetDir s n) = n
type HideDirection (SomeNetDir s n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (SomeNetDir s n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (SomeNetDir s n) = SomeNet n

_MkSomeNetDir :: forall (s :: Size) (d :: Direction) n. SingDirection d => Review (SomeNetDir s n) (NetBytes d s n) Source #

Review between SomeNetDir and underlying NetBytes. This is not an iso (i.e. only allows NetBytes -> SomeNetDir) because the opposite direction would require dropping the Direction and the user arbitrarily choosing a new one.

Examples

Expand
>>> import Optics.Core (review)
>>> review _MkSomeNetDir (MkNetBytesP @Up @K @Int 70)
MkSomeNetDir SUp (MkNetBytes (MkBytes 70))

Since: 0.1

someNetDirToSSize :: forall (s :: Size) n. SingSize s => SomeNetDir s n -> SSize s Source #

Retrieves the SingSize witness. Can be used to recover the Size.

Since: 0.1

Unknown Direction and Size

data SomeNet n where Source #

Wrapper for NetBytes, existentially quantifying the size and direction. This is useful when a function does not know a priori what size or direction it should return e.g.

>>> :{
  getMaxTraffic :: IO (SomeNet Double)
  getMaxTraffic = do
    -- getMaxTrafficNetRaw :: IO (Double, String, String)
    (bytes, direction, size) <- getMaxTrafficNetRaw
    pure $ case (direction, size) of
      ("Down", "K") -> hideDirection $ hideSize $ MkNetBytesP @Down @K bytes
      ("Up", "M") -> hideDirection $ hideSize $ MkNetBytesP @Up @M bytes
      _ -> error "todo"
:}

SomeNet carries along SDirection and SSize runtime witnesses for recovering the Direction and Size, respectively.

This instance uses the same equivalence relation from SomeNetSize w.r.t the size, and also includes an equality check on the direction. Thus we have, for instance,

>>> let x = MkNetBytesP 1_000 :: NetBytes Up K Int
>>> let y = MkNetBytesP 1 :: NetBytes Up M Int
>>> let z = MkNetBytesP 1_000 :: NetBytes Down K Int
>>> hideDirection (hideSize x) == hideDirection (hideSize y)
True
>>> hideDirection (hideSize x) == hideDirection (hideSize z)
False

Since: 0.1

Constructors

MkSomeNet :: forall (d :: Direction) (s :: Size) n. SDirection d -> SSize s -> NetBytes d s n -> SomeNet n

Since: 0.1

Instances

Instances details
Functor SomeNet Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

fmap :: (a -> b) -> SomeNet a -> SomeNet b #

(<$) :: a -> SomeNet b -> SomeNet a #

Foldable SomeNet Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

fold :: Monoid m => SomeNet m -> m #

foldMap :: Monoid m => (a -> m) -> SomeNet a -> m #

foldMap' :: Monoid m => (a -> m) -> SomeNet a -> m #

foldr :: (a -> b -> b) -> b -> SomeNet a -> b #

foldr' :: (a -> b -> b) -> b -> SomeNet a -> b #

foldl :: (b -> a -> b) -> b -> SomeNet a -> b #

foldl' :: (b -> a -> b) -> b -> SomeNet a -> b #

foldr1 :: (a -> a -> a) -> SomeNet a -> a #

foldl1 :: (a -> a -> a) -> SomeNet a -> a #

toList :: SomeNet a -> [a] #

null :: SomeNet a -> Bool #

length :: SomeNet a -> Int #

elem :: Eq a => a -> SomeNet a -> Bool #

maximum :: Ord a => SomeNet a -> a #

minimum :: Ord a => SomeNet a -> a #

sum :: Num a => SomeNet a -> a #

product :: Num a => SomeNet a -> a #

Traversable SomeNet Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

traverse :: Applicative f => (a -> f b) -> SomeNet a -> f (SomeNet b) #

sequenceA :: Applicative f => SomeNet (f a) -> f (SomeNet a) #

mapM :: Monad m => (a -> m b) -> SomeNet a -> m (SomeNet b) #

sequence :: Monad m => SomeNet (m a) -> m (SomeNet a) #

HasField "unSomeNet" (SomeNet n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

getField :: SomeNet n -> n #

(k ~ A_Getter, a ~ n, b ~ n) => LabelOptic "unSomeNet" k (SomeNet n) (SomeNet n) a b Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

labelOptic :: Optic k NoIx (SomeNet n) (SomeNet n) a b Source #

Normed n => Normed (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

norm :: SomeNet n -> SomeNet n Source #

NFData n => NFData (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

rnf :: SomeNet n -> () #

Show n => Show (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

showsPrec :: Int -> SomeNet n -> ShowS #

show :: SomeNet n -> String #

showList :: [SomeNet n] -> ShowS #

(Eq n, FromInteger n, MGroup n) => Eq (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(==) :: SomeNet n -> SomeNet n -> Bool #

(/=) :: SomeNet n -> SomeNet n -> Bool #

(FromInteger n, Hashable n, MGroup n) => Hashable (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

(FromInteger n, MGroup n) => Conversion (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

convert_ :: forall (t :: Size). SingSize t => SomeNet n -> Converted t (SomeNet n) Source #

(FromInteger n, MGroup n, Normed n, Ord n) => Normalize (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type Norm (SomeNet n) 
Instance details

Defined in Data.Bytes.Network.Internal

type Norm (SomeNet n) = SomeNet n

Methods

normalize :: SomeNet n -> Norm (SomeNet n) Source #

Read n => Parser (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

RawNumeric (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type Raw (SomeNet n) 
Instance details

Defined in Data.Bytes.Network.Internal

type Raw (SomeNet n) = n

Methods

toRaw :: SomeNet n -> Raw (SomeNet n) Source #

Directed (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideDirection (SomeNet n) 
Instance details

Defined in Data.Bytes.Network.Internal

Sized (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Associated Types

type HideSize (SomeNet n) 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (SomeNet n) = SomeNet n
MSemigroup n => MSemiSpace (SomeNet n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.*) :: SomeNet n -> n -> SomeNet n Source #

MGroup n => MSpace (SomeNet n) n Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

(.%) :: SomeNet n -> n -> SomeNet n Source #

type Converted t (SomeNet n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Converted t (SomeNet n) = SomeNetDir t n
type Norm (SomeNet n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Norm (SomeNet n) = SomeNet n
type Raw (SomeNet n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type Raw (SomeNet n) = n
type HideDirection (SomeNet n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (SomeNet n) Source # 
Instance details

Defined in Data.Bytes.Network.Internal

type HideSize (SomeNet n) = SomeNet n

_MkSomeNet :: forall (s :: Size) (d :: Direction) n. (SingDirection d, SingSize s) => Review (SomeNet n) (NetBytes d s n) Source #

Review between SomeNet and underlying NetBytes. This is not an iso (i.e. only allows NetBytes -> SomeNet) because the opposite direction would require dropping the Direction and the user arbitrarily choosing a new one.

Examples

Expand
>>> import Optics.Core (review)
>>> review _MkSomeNet (MkNetBytesP @Up @K @Int 70)
MkSomeNet SUp SK (MkNetBytes (MkBytes 70))

Since: 0.1