import itertools


def trim_spec_composer(bins_seq, lefts=None, rights=None, axes=None):
    """
    Helps to compose trim_spec parameter in
    :py:func:`triniti_ne.rebin.trim_nd` with
    reasonable defaults for lefts, rights and axes iterators.

    Parameters
    ----------
    bins_seq: sequence of ndarrays
        Iterates over the list of bins associated with a grid to be trimmed.
    lefts: sequence of floats
        Iterates over the list of left edges for trimming.
    rights: sequence of floats
        Iterates over the list of right edges for trimming.
    axes: sequence of ints, optional
        Iterates over the list of corresponding axes.
        If not provided (default), then iterates over sequence 0..len(bins).

    Returns
    -------
    trim_spec: sequence of tuples
        Iterator over the sequence of tuples (bins, lefts, rights, axis)
    """
    if not lefts:
        lefts = itertools.repeat(None)
    if not rights:
        rights = itertools.repeat(None)
    if not axes:
        axes = itertools.count()
    return zip(bins_seq, lefts, rights, axes)