catchChecks
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kaigouthro
//@version=5

// @description Type Check for Function Builders to allow Single item to be
// passed in, and determine what to do with the item, ie: need an x value?
// function that allows label, line, box, float, or even a string..
// check item type? string ? 'str.tonumber(_item)' can be in the same
// switch as a 'line.get_price(_item, bar_index)' both outputting float
// or for pulling a value from simple, array, or matrix, one function
// that can switch between them. reduce overhead of many functions.
// there are many ways to use this tool, the simplest may be 
// string/floats on one switch or grabbing colors from line/fill/label
// please Share any great recipes you come up with!
library("catchChecks")

_arrdummy(_temp) => array.set  ( _temp , 0,     array.get(_temp, 0  ))
_mtxdummy(_temp) => matrix.set ( _temp , 0, 0, matrix.get(_temp, 0,0))
_nrmdummy(_temp) => _temp == _temp[1] ? '' : ''

// @function Input anything..       Determine what it is.
// @param    _temp        (any)     Matrix, Array, or Simple Item
// @param    _doMeth (bool)    True for M/A/S , false for int/float/string.. etc..
// @returns               (string)  Type of item checked.
export typeIs(int                _temp, bool _doMeth = false)=> _s   = _nrmdummy(_temp)              , (_doMeth ? 'simple' : 'int'     ) + _s
export typeIs(float              _temp, bool _doMeth = false)=> _s   = _nrmdummy(_temp)              , (_doMeth ? 'simple' : 'float'   ) + _s
export typeIs(bool               _temp, bool _doMeth = false)=> _s   = _nrmdummy(_temp)              , (_doMeth ? 'simple' : 'bool'    ) + _s
export typeIs(string             _temp, bool _doMeth = false)=> _s   = _nrmdummy(_temp)              , (_doMeth ? 'simple' : 'string'  ) + _s
export typeIs(color              _temp, bool _doMeth = false)=> _s   = _nrmdummy(_temp)              , (_doMeth ? 'simple' : 'color'   ) + _s
export typeIs(line               _temp, bool _doMeth = false)=> _tmp = _temp, line.delete     (_tmp) , (_doMeth ? 'simple' : 'line'    ) 
export typeIs(label              _temp, bool _doMeth = false)=> _tmp = _temp, label.delete    (_tmp) , (_doMeth ? 'simple' : 'label'   ) 
export typeIs(box                _temp, bool _doMeth = false)=> _tmp = _temp, box.delete      (_tmp) , (_doMeth ? 'simple' : 'box'     ) 
export typeIs(table              _temp, bool _doMeth = false)=> _tmp = _temp, table.delete    (_tmp) , (_doMeth ? 'simple' : 'table'   ) 
export typeIs(linefill           _temp, bool _doMeth = false)=> _tmp = _temp, linefill.delete (_tmp) , (_doMeth ? 'simple' : 'linefill') 
export typeIs(int      []        _temp, bool _doMeth = false)=> _arrdummy(_temp)                     , (_doMeth ? 'array'  : 'int'     ) 
export typeIs(float    []        _temp, bool _doMeth = false)=> _arrdummy(_temp)                     , (_doMeth ? 'array'  : 'float'   ) 
export typeIs(bool     []        _temp, bool _doMeth = false)=> _arrdummy(_temp)                     , (_doMeth ? 'array'  : 'bool'    ) 
export typeIs(string   []        _temp, bool _doMeth = false)=> _arrdummy(_temp)                     , (_doMeth ? 'array'  : 'string'  ) 
export typeIs(color    []        _temp, bool _doMeth = false)=> _arrdummy(_temp)                     , (_doMeth ? 'array'  : 'color'   ) 
export typeIs(line     []        _temp, bool _doMeth = false)=> _arrdummy(_temp)                     , (_doMeth ? 'array'  : 'line'    ) 
export typeIs(label    []        _temp, bool _doMeth = false)=> _arrdummy(_temp)                     , (_doMeth ? 'array'  : 'label'   ) 
export typeIs(box      []        _temp, bool _doMeth = false)=> _arrdummy(_temp)                     , (_doMeth ? 'array'  : 'box'     ) 
export typeIs(table    []        _temp, bool _doMeth = false)=> _arrdummy(_temp)                     , (_doMeth ? 'array'  : 'table'   ) 
export typeIs(linefill []        _temp, bool _doMeth = false)=> _arrdummy(_temp)                     , (_doMeth ? 'array'  : 'linefill') 
export typeIs(matrix   <int>     _temp, bool _doMeth = false)=> _mtxdummy(_temp)                     , (_doMeth ? 'matrix' : 'int'     ) 
export typeIs(matrix   <float>   _temp, bool _doMeth = false)=> _mtxdummy(_temp)                     , (_doMeth ? 'matrix' : 'float'   ) 
export typeIs(matrix   <bool>    _temp, bool _doMeth = false)=> _mtxdummy(_temp)                     , (_doMeth ? 'matrix' : 'bool'    ) 
export typeIs(matrix   <string>  _temp, bool _doMeth = false)=> _mtxdummy(_temp)                     , (_doMeth ? 'matrix' : 'string'  ) 
export typeIs(matrix   <color>   _temp, bool _doMeth = false)=> _mtxdummy(_temp)                     , (_doMeth ? 'matrix' : 'color'   ) 
export typeIs(matrix   <line>    _temp, bool _doMeth = false)=> _mtxdummy(_temp)                     , (_doMeth ? 'matrix' : 'line'    ) 
export typeIs(matrix   <label>   _temp, bool _doMeth = false)=> _mtxdummy(_temp)                     , (_doMeth ? 'matrix' : 'label'   ) 
export typeIs(matrix   <box>     _temp, bool _doMeth = false)=> _mtxdummy(_temp)                     , (_doMeth ? 'matrix' : 'box'     ) 
export typeIs(matrix   <table>   _temp, bool _doMeth = false)=> _mtxdummy(_temp)                     , (_doMeth ? 'matrix' : 'table'   ) 
export typeIs(matrix   <linefill>_temp, bool _doMeth = false)=> _mtxdummy(_temp)                     , (_doMeth ? 'matrix' : 'linefill') 

 
// demo 
lb1  = 0 == hour% 5 ?  label.new ( time , close , typeIs ( matrix.new<float>(1,1,0.5))                         , xloc = xloc.bar_time, size = size.large, color = #ffaa00) : label(na)
lb2  = 0 == hour% 7 ?  label.new ( time , close , typeIs ( array.new<label> (1, lb1 ))                         , xloc = xloc.bar_time, size = size.large, color = #99ccaa) : label(na)
lb3  = 0 == hour% 9 ?  label.new ( time , close , typeIs ( lb2                       )                         , xloc = xloc.bar_time, size = size.large, color = #aaffcc) : label(na)
lb1a = 0 == hour% 3 ?  label.new ( time , close , typeIs ( matrix.new<float>(1,1,0.5)                  , true ), xloc = xloc.bar_time, size = size.large, color = #ccaaff) : label(na)
lb2a = 0 == hour% 7 ?  label.new ( time , close , typeIs ( array.new<string>(1, label.get_text(lb1a )) , true ), xloc = xloc.bar_time, size = size.large, color = #ff6600) : label(na)
lb3a = 0 == hour% 11?  label.new ( time , close , typeIs ( lb2a                                        , true ), xloc = xloc.bar_time, size = size.large, color = #ff00ff) : label(na)

