def expand_gen(func):
  """
  Function decorator, which given a function func, generates a new function, g,
  that given a list of tuples, maps func over the list, and flattens the result.

  Note that the tuples are splatted into func.
  """

  def loop(rows):
    result = []
    for row in rows:
      temp = func(*row)
      if not isinstance(temp, list):
        temp = [temp]
      result += temp
    return result

  return loop