Function Repository Resource:

# TableQ

Similar to ArrayQ, except it allows for ragged collections of nested lists

Contributed by: Richard Hennigan (Wolfram Research)
 ResourceFunction["TableQ"][expr] gives True if expr is a table, and gives False otherwise. ResourceFunction["TableQ"][expr,patt] requires expr to be a table with a depth that matches the pattern patt. ResourceFunction["TableQ"][expr,patt,test] requires also that test yield True when applied to each of the table elements in expr.

## Details and Options

In a table, all parts at a particular level must not mix lists and non-lists.
ResourceFunction["TableQ"][expr,1] tests whether expr is a vector.
ResourceFunction["TableQ"][expr,_,NumberQ] tests whether expr is a numerical table at all levels.

## Examples

### Basic Examples

Test to see if an expression is a table:

 In[1]:=
 Out[1]=
 In[2]:=
 Out[2]=
 In[3]:=
 Out[3]=
 In[4]:=
 Out[4]=

A vector of numbers is a table:

 In[5]:=
 Out[5]=

At each level, lists and non-lists cannot be mixed:

 In[6]:=
 Out[6]=
 In[7]:=
 Out[7]=

A ragged collection of nested lists is a table:

 In[8]:=
 Out[8]=

### Scope

Test for a vector:

 In[9]:=
 Out[9]=

Test for a matrix:

 In[10]:=
 Out[10]=
 In[11]:=
 Out[11]=

Test for a ragged table at level 2:

 In[12]:=
 Out[12]=
 In[13]:=
 Out[13]=

Test for a vector or a matrix:

 In[14]:=
 Out[14]=

Test for a numeric vector:

 In[15]:=
 Out[15]=

Test for an array of any depth with numeric entries:

 In[16]:=
 Out[16]=

### Applications

Define a function that only evaluates with tables of strings:

 In[17]:=
 In[18]:=
 Out[18]=
 In[19]:=
 Out[19]=

### Properties and Relations

VectorQ is a special case of TableQ:

 In[20]:=
 In[21]:=
 Out[21]=
 In[22]:=
 Out[22]=
 In[23]:=
 Out[23]=

ArrayQ implies TableQ:

 In[24]:=
 Out[24]=
 In[25]:=
 Out[25]=
 In[26]:=
 Out[26]=
 In[27]:=
 Out[27]=

The converse is not necessarily true:

 In[28]:=
 Out[28]=
 In[29]:=
 Out[29]=
 In[30]:=
 Out[30]=
 In[31]:=
 Out[31]=

TableQ[expr,_] is equivalent to ListQ[expr]:

 In[32]:=
 Out[32]=
 In[33]:=
 Out[33]=
 In[34]:=
 Out[34]=
 In[35]:=
 Out[35]=

In TableQ[expr,_,test], the result will be True if test returns True for all elements of any level:

 In[36]:=
 Out[36]=

This would normally return False due to mixing lists with non-lists:

 In[37]:=
 Out[37]=

## Requirements

Wolfram Language 11.3 (March 2018) or above