def dump_with_fn(dump_fn, data, stream, **options):
    """
    Dump `data` to a string if `stream` is None, or dump `data` to a file or
    file-like object `stream`.

    :param dump_fn: Callable to dump data
    :param data: Data to dump
    :param stream:  File or file like object or None
    :param options: optional keyword parameters

    :return: String represents data if stream is None or None
    """
    if stream is None:
        return dump_fn(data, **options)

    dump_fn(data, stream, **options)