<commit_before>class Parcel { ... }

class List {
    # Attributes defined in BOOTSTRAP.pm:
    #   has Mu $!items;        # RPA of our reified elements
    #   has $!nextiter;        # iterator for generating remaining elements

    method at_pos(\$pos) {
        self.exists($pos)
          ?? pir::set__PQi($!items, pir::repr_unbox_int__IP($pos))
          !! Mu
    }

    method eager() {
        self.gimme(100) while $!nextiter.defined;
    }

    method exists(\$pos) {
        self.gimme($pos + 1);
        pir::perl6_booleanize__PI(
            pir::exists__IQI($!items, pir::repr_unbox_int__IP($pos)))
    }

    method gimme($n) {
        pir::defined($!items) or 
            pir::setattribute__3PPsP(self, List, '$!items', pir::new__Ps('ResizablePMCArray'));
        my $count = pir::perl6_box_int__PI(pir::elements($!items));
        while $!nextiter.defined && $count < $n {
            $!nextiter.reify($n - $count);
            pir::setattribute__vPPsP(self, List, '$!nextiter', $!nextiter.nextiter);
            $count = pir::perl6_box_int__PI(pir::elements($!items));
        }
        pir::perl6_box_int__PI(pir::elements($!items))
    }

    method iterator() {
        # Return a Parcel containing our currently reified elements
        # and any subsequent iterator.
        my Mu $rpa := pir::clone__PP($!items);
        pir::push__vPP($rpa, $!nextiter) if $!nextiter.defined;<commit_msg>A naive implementation of List.gimme(*) .  Handling infinity will come shortly.<commit_after>class Parcel { ... }

class List {
    # Attributes defined in BOOTSTRAP.pm:
    #   has Mu $!items;        # RPA of our reified elements
    #   has $!nextiter;        # iterator for generating remaining elements

    method Bool() { self.gimme(1).Bool }

    method flat() { self.iterator.flat }
    method list() { self }


    method at_pos(\$pos) {
        self.exists($pos)
          ?? pir::set__PQi($!items, pir::repr_unbox_int__IP($pos))
          !! Mu
    }

    method eager() { self.gimme(*); self }

    method elems() {
        my $n = self.gimme(*);
        $!nextiter.defined ?? pir::perl6_box_num__PN('Inf') !! $n
    }

    method exists(\$pos) {
        self.gimme($pos + 1);
        pir::perl6_booleanize__PI(
            pir::exists__IQI($!items, pir::repr_unbox_int__IP($pos)))
    }

    method gimme($n) {
        pir::defined($!items) or 
            pir::setattribute__3PPsP(self, List, '$!items', pir::new__Ps('ResizablePMCArray'));
        my $count = pir::perl6_box_int__PI(pir::elements($!items));
        my $eager = Whatever.ACCEPTS($n);
        while $!nextiter.defined && ($eager || $count < $n) {
            $!nextiter.reify($eager ?? 100 !! $n - $count);
            pir::setattribute__vPPsP(self, List, '$!nextiter', $!nextiter.nextiter);
            $count = pir::perl6_box_int__PI(pir::elements($!items));
        }
        $count
    }

    method iterator() {
        # Return a Parcel containing our currently reified elements
        # and any subsequent iterator.
        my Mu $rpa := pir::clone__PP($!items);
        pir::push__vPP($rpa, $!nextiter) if $!nextiter.defined;
{'fraction_non_alphanumeric': 0.15451055662188098, 'fraction_numerical': 0.006078055022392835, 'mean_word_length': 2.577803203661327, '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': '7439675', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1020, 'n_words': 204}