import itertools


def _expand(the_set, expand_fn):
  """Returns a concatenation of the expanded sets.

  I.e.
  Returns a set of all elements returned by the expand_fn function for all
  elements in the_set.

  E.g.
  With expand_fn = lambda x: (10*x, 100*x) and the_set = set([1, 2, 3])
  this function returns set([10, 100, 20, 200, 30, 300])

  Args:
    the_set: A set of elements.
    expand_fn: Function returning an interable given some element in the_set.

  Returns: a concatenation of the expanded sets.
  """
  return set(itertools.chain(*[expand_fn(x) for x in the_set]))