intuicio_frontend_simpleton/library/
iter.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
use crate::{library::closure::Closure, Array, Boolean, Function, Integer, Map, Reference};
use intuicio_core::{context::Context, registry::Registry, IntuicioStruct};
use intuicio_derive::{intuicio_function, intuicio_method, intuicio_methods, IntuicioStruct};

const GENERATOR: &str = "next";

#[intuicio_function(module_name = "iter", use_context, use_registry)]
pub fn next(context: &mut Context, registry: &Registry, iterator: Reference) -> Reference {
    let iter = iterator.clone();
    if let Some(closure) = iterator.read::<Closure>() {
        closure.invoke(context, registry, &[iter])
    } else if let Some(map) = iterator.read::<Map>() {
        map.get(GENERATOR)
            .unwrap()
            .read::<Closure>()
            .unwrap()
            .invoke(context, registry, &[iter])
    } else {
        let closure = {
            let iterator = iterator.read_object().unwrap();
            iterator.read_field::<Reference>(GENERATOR).unwrap().clone()
        };
        let closure = closure.read::<Closure>().unwrap();
        closure.invoke(context, registry, &[iter])
    }
}

pub fn build_impl(
    context: &mut Context,
    registry: &Registry,
    previous: Option<Reference>,
    next: &[Reference],
) -> Reference {
    if next.is_empty() {
        return previous.unwrap_or_default();
    }
    let current = &next[0];
    if let Some(current) = current.read::<Array>() {
        let function = current[0].read::<Function>().unwrap();
        for argument in current[1..].iter().rev() {
            context.stack().push(argument.to_owned());
        }
        if let Some(previous) = previous {
            context.stack().push(previous);
        }
        function.handle().unwrap().invoke(context, registry);
        let previous = context.stack().pop::<Reference>().unwrap();
        build_impl(context, registry, Some(previous), &next[1..])
    } else {
        build_impl(context, registry, Some(current.clone()), &next[1..])
    }
}

#[intuicio_function(module_name = "iter", use_context, use_registry)]
pub fn build(context: &mut Context, registry: &Registry, iterators: Reference) -> Reference {
    let iterators = iterators.read::<Array>().unwrap();
    build_impl(context, registry, None, &iterators)
}

#[intuicio_function(module_name = "iter", use_registry)]
pub fn enumerate(registry: &Registry, iterator: Reference) -> Reference {
    Reference::new(
        IterEnumerate {
            iterator,
            index: 0,
            next: Reference::new(
                Closure {
                    function: Function::by_name("next", "iter_enumerate", registry).unwrap(),
                    captured: vec![],
                },
                registry,
            ),
        },
        registry,
    )
}

#[intuicio_function(module_name = "iter", use_registry)]
pub fn walk(registry: &Registry, start: Reference, steps: Reference) -> Reference {
    Reference::new(
        IterWalk {
            current: *start.read::<Integer>().unwrap(),
            steps: *steps.read::<Integer>().unwrap(),
            next: Reference::new(
                Closure {
                    function: Function::by_name("next", "iter_walk", registry).unwrap(),
                    captured: vec![],
                },
                registry,
            ),
        },
        registry,
    )
}

#[intuicio_function(module_name = "iter", use_registry)]
pub fn range(registry: &Registry, from: Reference, to: Reference) -> Reference {
    let from = *from.read::<Integer>().unwrap();
    let to = *to.read::<Integer>().unwrap();
    Reference::new(
        IterWalk {
            current: from,
            steps: to - from,
            next: Reference::new(
                Closure {
                    function: Function::by_name("next", "iter_walk", registry).unwrap(),
                    captured: vec![],
                },
                registry,
            ),
        },
        registry,
    )
}

#[intuicio_function(module_name = "iter", use_registry)]
pub fn range_inclusive(registry: &Registry, from: Reference, to: Reference) -> Reference {
    let from = *from.read::<Integer>().unwrap();
    let to = *to.read::<Integer>().unwrap();
    let steps = to - from;
    Reference::new(
        IterWalk {
            current: from,
            steps: steps + steps.signum(),
            next: Reference::new(
                Closure {
                    function: Function::by_name("next", "iter_walk", registry).unwrap(),
                    captured: vec![],
                },
                registry,
            ),
        },
        registry,
    )
}

#[intuicio_function(module_name = "iter", use_registry)]
pub fn filter(registry: &Registry, iterator: Reference, closure: Reference) -> Reference {
    Reference::new(
        IterFilter {
            iterator,
            closure,
            next: Reference::new(
                Closure {
                    function: Function::by_name("next", "iter_filter", registry).unwrap(),
                    captured: vec![],
                },
                registry,
            ),
        },
        registry,
    )
}

#[intuicio_function(module_name = "iter", use_registry)]
pub fn map(registry: &Registry, iterator: Reference, closure: Reference) -> Reference {
    Reference::new(
        IterMap {
            iterator,
            closure,
            next: Reference::new(
                Closure {
                    function: Function::by_name("next", "iter_map", registry).unwrap(),
                    captured: vec![],
                },
                registry,
            ),
        },
        registry,
    )
}

#[intuicio_function(module_name = "iter", use_registry)]
pub fn filter_map(registry: &Registry, iterator: Reference, closure: Reference) -> Reference {
    Reference::new(
        IterFilterMap {
            iterator,
            closure,
            next: Reference::new(
                Closure {
                    function: Function::by_name("next", "iter_filter_map", registry).unwrap(),
                    captured: vec![],
                },
                registry,
            ),
        },
        registry,
    )
}

#[intuicio_function(module_name = "iter", use_registry)]
pub fn flatten(registry: &Registry, iterator: Reference) -> Reference {
    Reference::new(
        IterFlatten {
            iterator,
            current: Reference::null(),
            next: Reference::new(
                Closure {
                    function: Function::by_name("next", "iter_flatten", registry).unwrap(),
                    captured: vec![],
                },
                registry,
            ),
        },
        registry,
    )
}

#[intuicio_function(module_name = "iter", use_registry)]
pub fn chain(registry: &Registry, iterators: Reference) -> Reference {
    Reference::new(
        IterChain {
            iterators: iterators.read::<Array>().unwrap().clone(),
            current: 0,
            next: Reference::new(
                Closure {
                    function: Function::by_name("next", "iter_chain", registry).unwrap(),
                    captured: vec![],
                },
                registry,
            ),
        },
        registry,
    )
}

#[intuicio_function(module_name = "iter", use_registry)]
pub fn zip(registry: &Registry, iterators: Reference) -> Reference {
    Reference::new(
        IterZip {
            iterators: iterators.read::<Array>().unwrap().clone(),
            next: Reference::new(
                Closure {
                    function: Function::by_name("next", "iter_zip", registry).unwrap(),
                    captured: vec![],
                },
                registry,
            ),
        },
        registry,
    )
}

#[intuicio_function(module_name = "iter", use_registry)]
pub fn chunks(registry: &Registry, iterator: Reference, count: Reference) -> Reference {
    Reference::new(
        IterChunks {
            iterator,
            count,
            next: Reference::new(
                Closure {
                    function: Function::by_name("next", "iter_chunks", registry).unwrap(),
                    captured: vec![],
                },
                registry,
            ),
        },
        registry,
    )
}

#[intuicio_function(module_name = "iter", use_context, use_registry)]
pub fn fold(
    context: &mut Context,
    registry: &Registry,
    iterator: Reference,
    mut start: Reference,
    closure: Reference,
) -> Reference {
    loop {
        let value = crate::library::iter::next(context, registry, iterator.clone());
        if value.is_null() {
            return start;
        }
        let closure = closure.read::<Closure>().unwrap();
        start = closure.invoke(context, registry, &[start.clone(), value]);
    }
}

#[intuicio_function(module_name = "iter", use_context, use_registry)]
pub fn find(
    context: &mut Context,
    registry: &Registry,
    iterator: Reference,
    closure: Reference,
) -> Reference {
    loop {
        let value = crate::library::iter::next(context, registry, iterator.clone());
        if value.is_null() {
            return value;
        }
        let closure = closure.read::<Closure>().unwrap();
        let result = closure.invoke(context, registry, &[value.clone()]);
        if *result.read::<Boolean>().unwrap() {
            return value;
        }
    }
}

#[intuicio_function(module_name = "iter", use_context, use_registry)]
pub fn find_map(
    context: &mut Context,
    registry: &Registry,
    iterator: Reference,
    closure: Reference,
) -> Reference {
    loop {
        let value = crate::library::iter::next(context, registry, iterator.clone());
        if value.is_null() {
            return value;
        }
        let closure = closure.read::<Closure>().unwrap();
        let result = closure.invoke(context, registry, &[value]);
        if !result.is_null() {
            return result;
        }
    }
}

#[intuicio_function(module_name = "iter", use_context, use_registry)]
pub fn position(
    context: &mut Context,
    registry: &Registry,
    iterator: Reference,
    closure: Reference,
) -> Reference {
    let mut index = 0;
    loop {
        let value = crate::library::iter::next(context, registry, iterator.clone());
        if value.is_null() {
            return value;
        }
        let closure = closure.read::<Closure>().unwrap();
        let result = closure.invoke(context, registry, &[value]);
        if *result.read::<Boolean>().unwrap() {
            return Reference::new_integer(index, registry);
        }
        index += 1;
    }
}

#[intuicio_function(module_name = "iter", use_context, use_registry)]
pub fn any(
    context: &mut Context,
    registry: &Registry,
    iterator: Reference,
    closure: Reference,
) -> Reference {
    loop {
        let value = crate::library::iter::next(context, registry, iterator.clone());
        if value.is_null() {
            return Reference::new_boolean(false, registry);
        }
        let closure = closure.read::<Closure>().unwrap();
        let result = closure.invoke(context, registry, &[value]);
        if *result.read::<Boolean>().unwrap() {
            return Reference::new_boolean(true, registry);
        }
    }
}

#[intuicio_function(module_name = "iter", use_context, use_registry)]
pub fn all(
    context: &mut Context,
    registry: &Registry,
    iterator: Reference,
    closure: Reference,
) -> Reference {
    loop {
        let value = crate::library::iter::next(context, registry, iterator.clone());
        if value.is_null() {
            return Reference::new_boolean(true, registry);
        }
        let closure = closure.read::<Closure>().unwrap();
        let result = closure.invoke(context, registry, &[value]);
        if !*result.read::<Boolean>().unwrap() {
            return Reference::new_boolean(false, registry);
        }
    }
}

#[intuicio_function(module_name = "iter", use_context, use_registry)]
pub fn count(context: &mut Context, registry: &Registry, iterator: Reference) -> Reference {
    let mut result = 0;
    loop {
        let value = crate::library::iter::next(context, registry, iterator.clone());
        if value.is_null() {
            return Reference::new_integer(result, registry);
        }
        result += 1;
    }
}

#[intuicio_function(module_name = "iter", use_context, use_registry)]
pub fn compared_by(
    context: &mut Context,
    registry: &Registry,
    iterator: Reference,
    closure: Reference,
) -> Reference {
    let mut found = crate::library::iter::next(context, registry, iterator.clone());
    if found.is_null() {
        return Reference::null();
    }
    loop {
        let value = crate::library::iter::next(context, registry, iterator.clone());
        if value.is_null() {
            return found;
        }
        let closure = closure.read::<Closure>().unwrap();
        let result = closure.invoke(context, registry, &[value.clone(), found.clone()]);
        if *result.read::<Boolean>().unwrap() {
            found = value;
        }
    }
}

#[derive(IntuicioStruct, Default)]
#[intuicio(name = "IterWalk", module_name = "iter_walk")]
pub struct IterWalk {
    #[intuicio(ignore)]
    pub current: Integer,
    #[intuicio(ignore)]
    pub steps: Integer,
    pub next: Reference,
}

#[intuicio_methods(module_name = "iter_walk")]
impl IterWalk {
    #[intuicio_method(use_registry)]
    pub fn next(registry: &Registry, mut iterator: Reference) -> Reference {
        let mut iterator = iterator.write::<IterWalk>().unwrap();
        if iterator.steps.abs() == 0 {
            return Reference::null();
        }
        let value = iterator.current;
        let step = iterator.steps.signum();
        iterator.current += step;
        iterator.steps -= step;
        Reference::new_integer(value, registry)
    }
}

#[derive(IntuicioStruct, Default)]
#[intuicio(name = "Enumeration", module_name = "iter")]
pub struct Enumeration {
    pub index: Reference,
    pub value: Reference,
}

#[derive(IntuicioStruct, Default)]
#[intuicio(name = "IterEnumerate", module_name = "iter_enumerate")]
pub struct IterEnumerate {
    #[intuicio(ignore)]
    pub iterator: Reference,
    #[intuicio(ignore)]
    pub index: usize,
    pub next: Reference,
}

#[intuicio_methods(module_name = "iter_enumerate")]
impl IterEnumerate {
    #[intuicio_method(use_context, use_registry)]
    pub fn next(context: &mut Context, registry: &Registry, mut iterator: Reference) -> Reference {
        let mut iterator = iterator.write::<IterEnumerate>().unwrap();
        let value = next(context, registry, iterator.iterator.clone());
        if value.is_null() {
            return Reference::null();
        }
        let index = iterator.index;
        iterator.index += 1;
        Reference::new(
            Enumeration {
                index: Reference::new_integer(index as Integer, registry),
                value,
            },
            registry,
        )
    }
}

#[derive(IntuicioStruct, Default)]
#[intuicio(name = "IterFilter", module_name = "iter_filter")]
pub struct IterFilter {
    #[intuicio(ignore)]
    pub iterator: Reference,
    #[intuicio(ignore)]
    pub closure: Reference,
    pub next: Reference,
}

#[intuicio_methods(module_name = "iter_filter")]
impl IterFilter {
    #[intuicio_method(use_context, use_registry)]
    pub fn next(context: &mut Context, registry: &Registry, iterator: Reference) -> Reference {
        let iterator = iterator.read::<IterFilter>().unwrap();
        loop {
            let value = next(context, registry, iterator.iterator.clone());
            if value.is_null() {
                return value;
            }
            let closure = iterator.closure.read::<Closure>().unwrap();
            let result = closure.invoke(context, registry, &[value.clone()]);
            if *result.read::<Boolean>().unwrap() {
                return value;
            }
        }
    }
}

#[derive(IntuicioStruct, Default)]
#[intuicio(name = "IterMap", module_name = "iter_map")]
pub struct IterMap {
    #[intuicio(ignore)]
    pub iterator: Reference,
    #[intuicio(ignore)]
    pub closure: Reference,
    pub next: Reference,
}

#[intuicio_methods(module_name = "iter_map")]
impl IterMap {
    #[intuicio_method(use_context, use_registry)]
    pub fn next(context: &mut Context, registry: &Registry, iterator: Reference) -> Reference {
        let iterator = iterator.read::<IterMap>().unwrap();
        let value = next(context, registry, iterator.iterator.clone());
        if value.is_null() {
            value
        } else {
            let closure = iterator.closure.read::<Closure>().unwrap();
            closure.invoke(context, registry, &[value])
        }
    }
}

#[derive(IntuicioStruct, Default)]
#[intuicio(name = "IterMap", module_name = "iter_filter_map")]
pub struct IterFilterMap {
    #[intuicio(ignore)]
    pub iterator: Reference,
    #[intuicio(ignore)]
    pub closure: Reference,
    pub next: Reference,
}

#[intuicio_methods(module_name = "iter_filter_map")]
impl IterFilterMap {
    #[intuicio_method(use_context, use_registry)]
    pub fn next(context: &mut Context, registry: &Registry, iterator: Reference) -> Reference {
        let iterator = iterator.read::<IterFilterMap>().unwrap();
        loop {
            let value = next(context, registry, iterator.iterator.clone());
            if value.is_null() {
                return value;
            }
            let closure = iterator.closure.read::<Closure>().unwrap();
            let result = closure.invoke(context, registry, &[value]);
            if !result.is_null() {
                return result;
            }
        }
    }
}

#[derive(IntuicioStruct, Default)]
#[intuicio(name = "IterFlatten", module_name = "iter_flatten")]
pub struct IterFlatten {
    #[intuicio(ignore)]
    pub iterator: Reference,
    #[intuicio(ignore)]
    pub current: Reference,
    pub next: Reference,
}

#[intuicio_methods(module_name = "iter_flatten")]
impl IterFlatten {
    #[intuicio_method(use_context, use_registry)]
    pub fn next(context: &mut Context, registry: &Registry, mut iterator: Reference) -> Reference {
        let mut iterator = iterator.write::<IterFlatten>().unwrap();
        loop {
            if iterator.current.is_null() {
                iterator.current = next(context, registry, iterator.iterator.clone());
                if iterator.current.is_null() {
                    return Reference::null();
                }
            }
            let value = next(context, registry, iterator.current.clone());
            if value.is_null() {
                iterator.current = Reference::null()
            } else {
                return value;
            }
        }
    }
}

#[derive(IntuicioStruct, Default)]
#[intuicio(name = "IterChain", module_name = "iter_chain")]
pub struct IterChain {
    #[intuicio(ignore)]
    pub iterators: Array,
    #[intuicio(ignore)]
    pub current: usize,
    pub next: Reference,
}

#[intuicio_methods(module_name = "iter_chain")]
impl IterChain {
    #[intuicio_method(use_context, use_registry)]
    pub fn next(context: &mut Context, registry: &Registry, mut iterator: Reference) -> Reference {
        let mut iterator = iterator.write::<IterChain>().unwrap();
        while let Some(current) = iterator.iterators.get(iterator.current) {
            let value = next(context, registry, current.clone());
            if value.is_null() {
                iterator.current += 1;
            } else {
                return value;
            }
        }
        Reference::null()
    }
}

#[derive(IntuicioStruct, Default)]
#[intuicio(name = "IterZip", module_name = "iter_zip")]
pub struct IterZip {
    #[intuicio(ignore)]
    pub iterators: Array,
    pub next: Reference,
}

#[intuicio_methods(module_name = "iter_zip")]
impl IterZip {
    #[intuicio_method(use_context, use_registry)]
    pub fn next(context: &mut Context, registry: &Registry, iterator: Reference) -> Reference {
        let iterator = iterator.read::<IterZip>().unwrap();
        let result = iterator
            .iterators
            .iter()
            .map(|iterator| next(context, registry, iterator.clone()))
            .collect::<Array>();
        if result.iter().any(|value| value.is_null()) {
            Reference::null()
        } else {
            Reference::new_array(result, registry)
        }
    }
}

#[derive(IntuicioStruct, Default)]
#[intuicio(name = "IterChunks", module_name = "iter_chunks")]
pub struct IterChunks {
    #[intuicio(ignore)]
    pub iterator: Reference,
    #[intuicio(ignore)]
    pub count: Reference,
    pub next: Reference,
}

#[intuicio_methods(module_name = "iter_chunks")]
impl IterChunks {
    #[intuicio_method(use_context, use_registry)]
    pub fn next(context: &mut Context, registry: &Registry, iterator: Reference) -> Reference {
        let iterator = iterator.read::<IterChunks>().unwrap();
        let count = *iterator.count.read::<Integer>().unwrap() as usize;
        if count == 0 {
            return Reference::null();
        }
        let mut result = Vec::with_capacity(count);
        for _ in 0..count {
            let value = next(context, registry, iterator.iterator.clone());
            if value.is_null() {
                return Reference::null();
            }
            result.push(value);
        }
        Reference::new_array(result, registry)
    }
}

pub fn install(registry: &mut Registry) {
    registry.add_function(next::define_function(registry));
    registry.add_function(build::define_function(registry));
    registry.add_function(walk::define_function(registry));
    registry.add_function(range::define_function(registry));
    registry.add_function(range_inclusive::define_function(registry));
    registry.add_function(enumerate::define_function(registry));
    registry.add_function(filter::define_function(registry));
    registry.add_function(map::define_function(registry));
    registry.add_function(filter_map::define_function(registry));
    registry.add_function(flatten::define_function(registry));
    registry.add_function(chain::define_function(registry));
    registry.add_function(zip::define_function(registry));
    registry.add_function(chunks::define_function(registry));
    registry.add_function(fold::define_function(registry));
    registry.add_function(find::define_function(registry));
    registry.add_function(find_map::define_function(registry));
    registry.add_function(position::define_function(registry));
    registry.add_function(any::define_function(registry));
    registry.add_function(all::define_function(registry));
    registry.add_function(count::define_function(registry));
    registry.add_function(compared_by::define_function(registry));
    registry.add_type(IterWalk::define_struct(registry));
    registry.add_function(IterWalk::next__define_function(registry));
    registry.add_type(Enumeration::define_struct(registry));
    registry.add_type(IterEnumerate::define_struct(registry));
    registry.add_function(IterEnumerate::next__define_function(registry));
    registry.add_type(IterFilter::define_struct(registry));
    registry.add_function(IterFilter::next__define_function(registry));
    registry.add_type(IterMap::define_struct(registry));
    registry.add_function(IterMap::next__define_function(registry));
    registry.add_type(IterFilterMap::define_struct(registry));
    registry.add_function(IterFilterMap::next__define_function(registry));
    registry.add_type(IterFlatten::define_struct(registry));
    registry.add_function(IterFlatten::next__define_function(registry));
    registry.add_type(IterChain::define_struct(registry));
    registry.add_function(IterChain::next__define_function(registry));
    registry.add_type(IterZip::define_struct(registry));
    registry.add_function(IterZip::next__define_function(registry));
    registry.add_type(IterChunks::define_struct(registry));
    registry.add_function(IterChunks::next__define_function(registry));
}