title: chain join multiple arguments from a list of variable size using a supplied bivariate function
body: <p>I am looking to execute a function over all arguments in a list (<code>map</code> could do that part) and then "join" them using another function that could be exited early (say if the objective was to find an instance or reach a threshold).</p>
  
  <p>Here is an example where the function is <code>~np.isnan</code> over a variable number of columns from a data frame and the "join" is the bitwise <code>&amp;</code> operator on the resulting boolean masks. So it finds if there are any NaN values in a data frame, where the location corresponds to a variable list of columns. I then removes the rows where a NaN is found for the supplied column names.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import random
  
  data_values = range(10)
  column_names = list(map(lambda x: "C" + str(x), data_values))
  data = pd.DataFrame(columns=column_names, data=np.reshape(np.repeat(data_values,10,0),(10,10)))
  data.iloc[random.sample(data_values,random.sample(data_values,1)[0]),random.sample(data_values,random.sample(data_values,1)[0])] = np.nan
  cols_to_check = random.sample(column_names,random.sample(data_values,1)[0])
  # ideally: data.loc[pd.notnull(data[cols_to_check[0]]) &amp; pd.notnull(data[cols_to_check[1]]) &amp; ...]
  # or perhaps: data.loc[chainFunc(pd.notnull, np.logical_and, cols_to_check)]
  masks = [list(np.where(~np.isnan(data[x]))[0]) for x in cols_to_check]
  data.iloc[list(set(masks[0]).intersection(*masks))]
  </code></pre>
  
  <p>This becomes extremely slow on large data frames but is it possible to generalize this using the <code>itertools</code> and <code>functools</code> and drastically improve performance? Say something like (<em>pseudocode</em>):</p>
  
  <pre><code>def chainFunc(func_applied, func_chain, args):
      x = func_applied(args[0])
      for arg_counter in range(len(args)-1):
          x = func_chain(x,func_applied(args[arg_counter+1]))
      return(x)
  </code></pre>
  
  <p>How would it work on the data frame example above?</p>