def unionIntervals(intervals):
   """
   unionIntervals(intervals)

   Return a list of union interval(s) of the input intervals, e.g., 
   given [[1,2], [4,6], [5,8]] will result in [[1,2], [4,8]].


   PARAMETERS

   intervals: list or sequence-like
      list of lists/tuples defining the intervals, e.g., [[0,1], [5,8], ...]

   RETURN

   union_intervals: list
      list of list(s) defining the union interval(s)
   
   """
   union_intervals = []
   for interval in sorted(intervals):
      interval = list(interval)
      if union_intervals and union_intervals[-1][1] >= interval[0]:
         union_intervals[-1][1] = max(union_intervals[-1][1], interval[1])
      else:
         union_intervals.append(interval)
   return union_intervals