{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeSynonymInstances #-}

module Control.Process.Pid(
  HasPid(..)
, AsPid(..)
) where

import Control.Category((.), id)
import Control.Lens ( iso, Lens', Prism' )
import Data.Int ( Int32 )
import System.Posix.Types ( CPid(CPid) )
import System.Process ( Pid )

class HasPid a where
  pid ::
    Lens' a Pid
  pidInt32 ::
    Lens' a Int32
  pidInt32 =
    (Pid -> f Pid) -> a -> f a
forall a. HasPid a => Lens' a Pid
pid ((Pid -> f Pid) -> a -> f a)
-> ((Int32 -> f Int32) -> Pid -> f Pid)
-> (Int32 -> f Int32)
-> a
-> f a
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
      (Pid -> Int32) -> (Int32 -> Pid) -> Iso Pid Pid Int32 Int32
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
        (\(CPid Int32
x) -> Int32
x)
        Int32 -> Pid
CPid

instance HasPid Pid where
  pid :: (Pid -> f Pid) -> Pid -> f Pid
pid =
    (Pid -> f Pid) -> Pid -> f Pid
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id

class AsPid a where
  _Pid ::
    Prism' a Pid
  _PidInt32 ::
    Prism' a Int32
  _PidInt32 =
    p Pid (f Pid) -> p a (f a)
forall a. AsPid a => Prism' a Pid
_Pid (p Pid (f Pid) -> p a (f a))
-> (p Int32 (f Int32) -> p Pid (f Pid))
-> p Int32 (f Int32)
-> p a (f a)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.
      (Pid -> Int32) -> (Int32 -> Pid) -> Iso Pid Pid Int32 Int32
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
        (\(CPid Int32
x) -> Int32
x)
        Int32 -> Pid
CPid

instance AsPid Pid where
  _Pid :: p Pid (f Pid) -> p Pid (f Pid)
_Pid =
    p Pid (f Pid) -> p Pid (f Pid)
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id