@Nonnull
    public static Function<String[], String[]> createFieldProjection(
            @Nonnull String[] inputFields,
            @Nonnull List<String> outputFields
    ) {
        if (outputFields.equals(asList(inputFields))) {
            // shortcut - the mapping is an identity
            return i -> i;
        }
        int[] simpleFieldMap = new int[outputFields.size()];
        Arrays.fill(simpleFieldMap, -1);
        for (int i = 0; i < inputFields.length; i++) {
            int index = outputFields.indexOf(inputFields[i]);
            // if the inputFields is present in the file and we didn't encounter it yet, store its index
            if (index >= 0 && simpleFieldMap[index] == -1) {
                simpleFieldMap[index] = i;
            }
        }

        return row0 -> {
            String[] projectedRow = new String[simpleFieldMap.length];
            for (int i = 0; i < simpleFieldMap.length; i++) {
                if (simpleFieldMap[i] >= 0) {
                    projectedRow[i] = row0[simpleFieldMap[i]];
                }
            }
            return projectedRow;
        };
    }
@Test
    public void test_createFieldProjection() {
        Function<String[], String[]> fieldProjection =
                createFieldProjection(new String[]{"c", "a", "d", "a"}, asList("a", "b", "c"));
        assertArrayEquals(new String[]{"a", null, "c"}, fieldProjection.apply(new String[]{"c", "a", "d"}));
    }