use crate::frontend::iter::{EnumerateExpand, RevExpand, SkipExpand, TakeExpand, ZipExpand};
use crate::prelude::*;
pub trait IndexedIteratorExpand: IteratorExpand {
fn __expand_len_method(&self, scope: &Scope) -> NativeExpand<usize>;
fn get(&mut self, scope: &Scope, index: NativeExpand<usize>) -> Self::Item;
fn __expand_zip_method<U>(
self,
scope: &Scope,
other: IterArg<U>,
) -> ZipExpand<Self, U::IntoIter>
where
U: IntoIteratorExpand,
{
ZipExpand::new(self, other.0.__expand_into_iter_method(scope))
}
fn __expand_enumerate_method(self, _scope: &Scope) -> EnumerateExpand<Self> {
EnumerateExpand::new(self)
}
fn __expand_rev_method(self, _scope: &Scope) -> RevExpand<Self> {
RevExpand::new(self)
}
fn __expand_take_method(self, _scope: &Scope, n: NativeExpand<usize>) -> TakeExpand<Self> {
TakeExpand::new(self, n)
}
fn __expand_skip_method(self, _scope: &Scope, n: NativeExpand<usize>) -> SkipExpand<Self> {
SkipExpand::new(self, n)
}
}
pub(crate) fn expand_indexed<I: IndexedIteratorExpand>(
mut iter: I,
scope: &Scope,
body: &mut dyn FnMut(&Scope, I::Item),
) {
let start = NativeExpand::<usize>::from_lit(scope, 0);
let end = iter.__expand_len_method(scope);
RangeExpand::new(start, end).expand(scope, &mut |scope, index| {
let item = iter.get(scope, index);
body(scope, item);
});
}