human
I wrote the below code

    name = ('map-%s-%s' % (funcname(func), tokenize(func, args, kwargs)))
    dsk = {}
    bags = []
    args2 = []
    for a in args:
        if isinstance(a, Bag):
            bags.append(a)
            args2.append(a)
            dsk.update(a.dask)
        elif isinstance(a, (Item, Delayed)):
            args2.append((itertools.repeat, a.key))
            dsk.update(ensure_dict(a.dask))
        else:
            args2.append((itertools.repeat, a))
    bag_kwargs = {}
    other_kwargs = {}
    for (k, v) in kwargs.items():
        if isinstance(v, Bag):
            bag_kwargs[k] = v
            bags.append(v)
            dsk.update(v.dask)
        else:
            other_kwargs[k] = v
    (kw_dsk, other_kwargs) = unpack_scalar_dask_kwargs(other_kwargs)
    dsk.update(kw_dsk)
    if (not bags):
        raise ValueError('At    least    one    argument    must    be    a    Bag.')
    npartitions = {b.npartitions for b in bags}
    if (len(npartitions) > 1):
        raise ValueError('All    bags    must    have    the    same    number    of    partitions.')
    npartitions = npartitions.pop()
    def build_args(n):
        return [((a.name, n) if isinstance(a, Bag) else a) for a in args2]
    def build_bag_kwargs(n):
        if (not bag_kwargs):
            return None
        return (dict, (zip, list(bag_kwargs), [(b.name, n) for b in bag_kwargs.values()]))
    dsk.update({(name, n): (reify, (map_chunk, func, build_args(n), build_bag_kwargs(n), other_kwargs)) for n in range(npartitions)})
    return_type = set(map(type, bags))
    return_type = (return_type.pop() if (len(return_type) == 1) else Bag)
    return return_type(dsk, name, npartitions)

What's a good function header?
assistant
#Here's a good function header.

def bag_map(func, *args, **kwargs):