surrealdb_expr/expr/statements/
foreach.rs1use common::range::IntegerRangeIter;
2
3use crate::expr::{Block, Expr, Param, Value};
4
5#[derive(Clone, Debug, Eq, PartialEq, Hash)]
6pub struct ForeachStatement {
7 pub param: Param,
8 pub range: Expr,
9 pub block: Block,
10}
11
12pub enum ForeachIter {
13 Array(std::vec::IntoIter<Value>),
14 Range(std::iter::Map<IntegerRangeIter, fn(i64) -> Value>),
15}
16
17impl Iterator for ForeachIter {
18 type Item = Value;
19
20 fn next(&mut self) -> Option<Self::Item> {
21 match self {
22 ForeachIter::Array(iter) => iter.next(),
23 ForeachIter::Range(iter) => iter.next(),
24 }
25 }
26}
27
28impl ForeachStatement {
29 pub fn read_only(&self) -> bool {
31 self.range.read_only() && self.block.read_only()
32 }
33}