def _sample_and_map(proj, parset, progset, progset_instructions,
    result_names, mapping_function, max_attempts, **kwargs):
    """
    Helper function to sample

    This function runs a sampled simulation and also calls an Ensemble's mapping
    function prior to returning. This means that the Result goes out of scope and
    is discarded. Used when performing parallel simulations via `Ensemble.run_sims()`
    (which is used for memory-constrained simulations)

    """
    results = proj.run_sampled_sims(n_samples=1, parset=parset, progset=
        progset, progset_instructions=progset_instructions, result_names=
        result_names, max_attempts=max_attempts)
    plotdata = mapping_function(results[0], **kwargs)
    return plotdata
