module Managed.Probe.Internal.Params
  ( params
  , paramsCnt
  , returns
  ) where

import Data.Typeable

expand :: TypeRep -> [TypeRep]
expand :: TypeRep -> [TypeRep]
expand TypeRep
x
  | [Char]
"->" <- TyCon -> [Char]
tyConName (TyCon -> [Char]) -> TyCon -> [Char]
forall a b. (a -> b) -> a -> b
$ TypeRep -> TyCon
typeRepTyCon TypeRep
x =
    [TypeRep] -> [TypeRep]
flatten ([TypeRep] -> [TypeRep]) -> [TypeRep] -> [TypeRep]
forall a b. (a -> b) -> a -> b
$ TypeRep -> [TypeRep]
typeRepArgs TypeRep
x
  | Bool
otherwise = [TypeRep
x]

flatten :: [TypeRep] -> [TypeRep]
flatten :: [TypeRep] -> [TypeRep]
flatten = (TypeRep -> [TypeRep]) -> [TypeRep] -> [TypeRep]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap TypeRep -> [TypeRep]
expand

params :: TypeRep -> [TypeRep]
params :: TypeRep -> [TypeRep]
params = [TypeRep] -> [TypeRep]
forall a. [a] -> [a]
init ([TypeRep] -> [TypeRep])
-> (TypeRep -> [TypeRep]) -> TypeRep -> [TypeRep]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeRep -> [TypeRep]
expand

paramsCnt :: TypeRep -> Int
paramsCnt :: TypeRep -> Int
paramsCnt = [TypeRep] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([TypeRep] -> Int) -> (TypeRep -> [TypeRep]) -> TypeRep -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeRep -> [TypeRep]
params

returns :: TypeRep -> TypeRep
returns :: TypeRep -> TypeRep
returns = [TypeRep] -> TypeRep
forall a. [a] -> a
last ([TypeRep] -> TypeRep)
-> (TypeRep -> [TypeRep]) -> TypeRep -> TypeRep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeRep -> [TypeRep]
expand