<commit_before>import OrderedPartition from './OrderedPartition';
import partialQuickSort from './partialQuickSort';
import quickSelect from './quickSelect';
import { Enumerable } from './Enumerable';
import { IPartition, partitionSymbol } from './partition';
import { noElements } from './errors';

const defualtComparer: (first: any, second: any) => number = (first, second) => 0;

export default class OrderedEnumerable<TElement, TKey> extends Enumerable<TElement> implements IPartition<TElement> {
    constructor(_source: Iterable<TElement>,
                private readonly _keySelector: (value: TElement) => TKey,
                private readonly _descending: boolean,
                private readonly _parentComparer: (first: TElement, second: TElement) => number = defualtComparer) {
        super(_source);
    }

    get source(): Iterable<TElement> {
        return this;
    }

    *[Symbol.iterator](): Iterator<TElement> {
        for (const element of this.toArray()) {
            yield element;
        }
    }

    [partitionSymbol](): boolean {
        return true;
    }

    thenBy<TKey>(keySelector: (value: TElement) => TKey): OrderedEnumerable<TElement, TKey> {
        return new OrderedEnumerable(this._source, keySelector, false, this._getComparer());
    }

    thenByDescending<TKey>(keySelector: (value: TElement) => TKey): OrderedEnumerable<TElement, TKey> {
        return new OrderedEnumerable(this._source, keySelector, true, this._getComparer());
    }

    take(count: number): Enumerable<TElement> {
        return new Enumerable(new OrderedPartition(this, 0, count - 1));
    }

    skip(count: number): Enumerable<TElement> {
        return new Enumerable(new OrderedPartition(this, count, Number.MAX_VALUE));
    }

    first(predicate?: (element: TElement) => boolean): TElement {
        const iterator = this._source[Symbol.iterator]();

        if (predicate) {
            let result: IteratorResult<TElement>;

            do {
                result = iterator.next();
                if (result.done) {
                    throw noElements();
                }
            } while (!predicate(result.value));

            const comparer = this._getComparer();<commit_msg>Improve OrderedEnumerable.skip()<commit_after>import OrderedPartition from './OrderedPartition';
import partialQuickSort from './partialQuickSort';
import quickSelect from './quickSelect';
import { Enumerable } from './Enumerable';
import { IPartition, partitionSymbol } from './partition';
import { noElements } from './errors';

const defualtComparer: (first: any, second: any) => number = (first, second) => 0;

export default class OrderedEnumerable<TElement, TKey> extends Enumerable<TElement> implements IPartition<TElement> {
    constructor(_source: Iterable<TElement>,
                private readonly _keySelector: (value: TElement) => TKey,
                private readonly _descending: boolean,
                private readonly _parentComparer: (first: TElement, second: TElement) => number = defualtComparer) {
        super(_source);
    }

    get source(): Iterable<TElement> {
        return this;
    }

    *[Symbol.iterator](): Iterator<TElement> {
        for (const element of this.toArray()) {
            yield element;
        }
    }

    [partitionSymbol](): boolean {
        return true;
    }

    thenBy<TKey>(keySelector: (value: TElement) => TKey): OrderedEnumerable<TElement, TKey> {
        return new OrderedEnumerable(this._source, keySelector, false, this._getComparer());
    }

    thenByDescending<TKey>(keySelector: (value: TElement) => TKey): OrderedEnumerable<TElement, TKey> {
        return new OrderedEnumerable(this._source, keySelector, true, this._getComparer());
    }

    take(count: number): Enumerable<TElement> {
        return new Enumerable(new OrderedPartition(this, 0, count - 1));
    }

    skip(count: number): Enumerable<TElement> {
        return new Enumerable(new OrderedPartition(this, count, Infinity));
    }

    first(predicate?: (element: TElement) => boolean): TElement {
        const iterator = this._source[Symbol.iterator]();

        if (predicate) {
            let result: IteratorResult<TElement>;

            do {
                result = iterator.next();
                if (result.done) {
                    throw noElements();
                }
            } while (!predicate(result.value));

            const comparer = this._getComparer();
{'fraction_non_alphanumeric': 0.11907436531116602, 'fraction_numerical': 0.0013480116827679174, 'mean_word_length': 2.925925925925926, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 43, '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': '2116665', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1182, 'n_words': 304}