Yield only the items in an iterable sequence that match the predicate
function filter(predicate) {
    return function* (iterable) {
        let index = 0;
        for (const value of iterable) {
            if (predicate(value, index)) {
                yield value;
            }
            index = index + 1;
        }
    };
}