package ru.ulstu.core.util;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

public class StreamApiUtils {

    public static <T, R> List<T> convert(List<R> entities, Function<R, T> converter) {
        return entities == null
                ? Collections.emptyList()
                : entities.stream().map(e -> converter.apply(e)).collect(Collectors.toList());
    }

    public static <T, R> Set<T> convert(Set<R> entities, Function<R, T> converter) {
        return entities == null
                ? Collections.emptySet()
                : entities.stream().map(e -> converter.apply(e)).collect(Collectors.toSet());
    }
}
