class Selectors {

    @SafeVarargs
    public static <Input, Output> SelectorFunction<Input, Output> firstAvailable(@NonNull final SelectorFunction<Input, Output> function,
                                                         final SelectorFunction<Input, Output>... functions) {
        return new SelectorFunction<Input, Output>() {

            @SuppressWarnings("unchecked")
            @Override
            public Output select(Input input) {
                Output result = function.select(input);
                if (result != null) {
                    return result;
                }

                for (SelectorFunction<Input, Output> selectorFunction : functions) {
                    result = selectorFunction.select(input);

                    if (result != null) {
                        return result;
                    }
                }

                return null;
            }
        };
    }

}