<commit_before>import ceylon.language {
    seq=sequence
}
"A [[Sequence]] backed by an [[Array]]. 
 
 Since [[Array]]s are mutable, this class is private to the
 language module, where we can be sure the `Array` is not
 modified after the `ArraySequence` has been initialized."
by ("Tom")
see (`function seq`)
shared sealed final
serializable
class ArraySequence<out Element>(array)
        extends Object()
        satisfies [Element+] {
    
    Array<Element> array;
    
    assert (!array.empty);
    
    getFromFirst(Integer index) 
            => array.getFromFirst(index);
    
    contains(Object element) 
            => array.contains(element);
    
    size => array.size;
    
    iterator() => array.iterator();
    
    shared actual Element first {
        if (exists first = array.first) {
            return first;
        }
        else {
            assert (is Element null);
            return null;
        }
    }
    
    shared actual Element last {
        if (exists last = array.last) {
            return last;
        }
        else {
            assert (is Element null);
            return null;
        }
    }
    
    rest => size == 1 
        then [] 
        else ArraySequence(array[1...]);
    
    clone() => ArraySequence(array.clone());
    
    each(void step(Element element)) => array.each(step);
    
    count(Boolean selecting(Element element))
            => array.count(selecting);
    
    every(Boolean selecting(Element element))
            => array.every(selecting);
    
    any(Boolean selecting(Element element))
            => array.any(selecting);
    
    find(Boolean selecting(Element&Object element))
            => array.find(selecting);
    
    findLast(Boolean selecting(Element&Object element))
            => array.findLast(selecting);
    
    shared actual 
    Result|Element reduce<Result>(
        Result accumulating(Result|Element partial, 
                            Element element)) {
        assert (exists result 
            = array.reduce(accumulating));
        return result;
    }

    shared actual 
    [Result+] collect<Result>
            (Result collecting(Element element)) {
        assert (nonempty sequence 
            = array.collect(collecting));
        return sequence;
    }
    
    shared actual 
    [Element+] sort
            (Comparison comparing(Element x, Element y)) {
        assert (nonempty sequence 
            = array.sort(comparing));
        return sequence;
    }
    
    shared actual 
    Element[] measure(Integer from, Integer length) {
        if (from > lastIndex || 
            length <= 0 || 
            from + length <= 0) {
            return [];
        }
        else if (from < 0) {
            return ArraySequence(array[0 : length + from]);
        }
        else {
            return ArraySequence(array[from:length]);
        }
    }
    
    shared actual 
    Element[] span(Integer from, Integer to) {
        if (from <= to) {
            return to < 0 || from > lastIndex
                then [] 
                else ArraySequence(array[from..to]);
        }
        else {
            return from < 0 || to > lastIndex
                then [] 
                else ArraySequence(array[from..to]);
        }
    }
    
    spanFrom(Integer from) 
            => from > lastIndex 
            then [] 
            else ArraySequence(array[from...]);
    
    spanTo(Integer to)
            => to < 0
            then []
            else ArraySequence(array[...to]);
    
    firstOccurrence(Anything element) 
            => array.firstOccurrence(element);
    
    lastOccurrence(Anything element) 
            => array.lastOccurrence(element);
}<commit_msg>oops, missed one<commit_after>import ceylon.language {
    seq=sequence
}
"A [[Sequence]] backed by an [[Array]]. 
 
 Since [[Array]]s are mutable, this class is private to the
 language module, where we can be sure the `Array` is not
 modified after the `ArraySequence` has been initialized."
by ("Tom")
see (`function seq`)
shared sealed final
serializable
class ArraySequence<out Element>(array)
        extends Object()
        satisfies [Element+] {
    
    Array<Element> array;
    
    assert (!array.empty);
    
    getFromFirst(Integer index) 
            => array.getFromFirst(index);
    
    contains(Object element) 
            => array.contains(element);
    
    size => array.size;
    
    iterator() => array.iterator();
    
    shared actual Element first {
        if (exists first = array.first) {
            return first;
        }
        else {
            assert (is Element null);
            return null;
        }
    }
    
    shared actual Element last {
        if (exists last = array.last) {
            return last;
        }
        else {
            assert (is Element null);
            return null;
        }
    }
    
    rest => size == 1 
        then [] 
        else ArraySequence(array[1...]);
    
    clone() => ArraySequence(array.clone());
    
    each(void step(Element element)) => array.each(step);
    
    count(Boolean selecting(Element element))
            => array.count(selecting);
    
    every(Boolean selecting(Element element))
            => array.every(selecting);
    
    any(Boolean selecting(Element element))
            => array.any(selecting);
    
    find(Boolean selecting(Element&Object element))
            => array.find(selecting);
    
    findLast(Boolean selecting(Element&Object element))
            => array.findLast(selecting);
    
    shared actual 
    Result|Element reduce<Result>(
        Result accumulating(Result|Element partial, 
                            Element element)) {
        assert (exists result 
            = array.reduce(accumulating));
        return result;
    }

    shared actual 
    [Result+] collect<Result>
            (Result collecting(Element element)) {
        assert (nonempty sequence 
            = array.collect(collecting));
        return sequence;
    }
    
    shared actual 
    [Element+] sort
            (Comparison comparing(Element x, Element y)) {
        assert (nonempty sequence 
            = array.sort(comparing));
        return sequence;
    }
    
    shared actual 
    Element[] measure(Integer from, Integer length) {
        if (from > lastIndex || 
            length <= 0 || 
            from + length <= 0) {
            return [];
        }
        else if (from < 0) {
            return ArraySequence(array[0 : length + from]);
        }
        else {
            return ArraySequence(array[from:length]);
        }
    }
    
    shared actual 
    Element[] span(Integer from, Integer to) {
        if (from <= to) {
            return to < 0 || from > lastIndex
                then [] 
                else ArraySequence(array[from..to]);
        }
        else {
            return from < 0 || to > lastIndex
                then [] 
                else ArraySequence(array[from..to]);
        }
    }
    
    spanFrom(Integer from) 
            => from > lastIndex 
            then [] 
            else ArraySequence(array[from...]);
    
    spanTo(Integer to)
            => to < 0
            then []
            else ArraySequence(array[...to]);
    
    firstOccurrence(Anything element) 
            => array.firstOccurrence(element);
    
    lastOccurrence(Anything element) 
            => array.lastOccurrence(element);
    
    occurs(Anything element) => array.occurs(element);
    
}
{'fraction_non_alphanumeric': 0.10462319615179048, 'fraction_numerical': 0.002405130946018172, 'mean_word_length': 1.6770386266094421, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 52, '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': '6875317', 'n_tokens_mistral': 1989, 'n_tokens_neox': 1909, 'n_words': 505}