def summarize(seq,field_name,func=None,msg=None):
    """
    Compute a summary of a given field (eg. count of different values). Resulting dictionary is either passed to `func`,
    or printed on screen (if `func is None`).
    :param seq: Datastream
    :param field_name: Field name to summarize
    :param func: Function to call after summary is obtained (which is after all stream processing). If `None`, summary is printed on screen.
    :param msg: Optional message to print before summary
    :return: Original stream
    """
    if field_name is None:
        return seq
    d = {}
    for x in seq:
        c = x.get(field_name)
        if c is not None:
            d[c] = d.get(c,0)+1
        yield x
    if func is not None:
        func(d)
    else:
        if len(d.keys())>0:
            if msg is not None: print(msg)
            for t in d.keys():
                print(" + {}: {}".format(t,d[t]))