<commit_before>var cadence = require('cadence')

function yes () { return true }

function Forward (cursor) {
    this._cursor = cursor
    this._index = cursor.index
}

Forward.prototype.next = cadence(function (step, condition) {
    condition = condition || yes
    step(function () {
        if (this._index < this._cursor.length) return true
        else step(function () {
            this._cursor.next(step())
            this._index = 0
        })
    }, function (more) {
        if (!more) {
            this.terminated = true
            step(null)
        } else {
            this._cursor.get(this._index++, step())
        }
    }, function (record) {
        if (condition(record)) {
            step(null, record)
        }
    })()
})

Forward.prototype.unlock = function () {
    this._cursor.unlock()
}

exports.forward = cadence(function (step, strata, key) {
    var condition = key == null ? strata.left : strata.key(key)
    step(function () {
        strata.iterator(condition, step())
    }, function (cursor) {
        return new Forward(cursor)
    })
})<commit_msg>Perform tests on key, not on record.<commit_after>var cadence = require('cadence')

function yes () { return true }

function Forward (cursor) {
    this._cursor = cursor
    this._index = cursor.index
}

Forward.prototype.next = cadence(function (step, condition) {
    condition = condition || yes
    step(function () {
        if (this._index < this._cursor.length) return true
        else step(function () {
            this._cursor.next(step())
            this._index = 0
        })
    }, function (more) {
        if (!more) {
            this.terminated = true
            step(null)
        } else {
            this._cursor.get(this._index++, step())
        }
    }, function (record, key) {
        if (condition(key)) {
            step(null, record, key)
        }
    })()
})

Forward.prototype.unlock = function () {
    this._cursor.unlock()
}

exports.forward = cadence(function (step, strata, key) {
    var condition = key == null ? strata.left : strata.key(key)
    step(function () {
        strata.iterator(condition, step())
    }, function (cursor) {
        return new Forward(cursor)
    })
})
{'fraction_non_alphanumeric': 0.13808664259927797, 'fraction_numerical': 0.0009025270758122744, 'mean_word_length': 2.1671428571428573, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6549070', 'n_tokens_mistral': 649, 'n_tokens_neox': 632, 'n_words': 148}