use super::funejson::Value; /// Split `items` into consecutive batches of at most `size`, in order. /// /// An empty list gives no batches rather than one empty batch, so a loop over /// the result never sends an empty request. /// /// # Panics /// Panics if `size` is less than 1: it is always a bug upstream, and "no /// limit" is the outage batching prevents. pub fn chunk(items: &[T], size: i64) -> Vec> { if size < 1 { panic!("size must be at least 1, received {}", size); } items.chunks(size as usize).map(|batch| batch.to_vec()).collect() } pub fn fune_vector(args: &[Value]) -> Value { // Refuse what the typed signature cannot hold, with the wording TypeScript // and Python use, rather than let the conversion below quietly change it. if let Value::Float(f) = args[1] { if f.fract() != 0.0 { panic!("size must be a whole number, received {}", f); } } Value::Arr( chunk(args[0].as_arr(), args[1].as_i64()) .into_iter() .map(Value::Arr) .collect(), ) }