polars_plan/dsl/functions/
repeat.rs

1use super::*;
2
3/// Create a column of length `n` containing `n` copies of the literal `value`.
4///
5/// Generally you won't need this function, as `lit(value)` already represents a column containing
6/// only `value` whose length is automatically set to the correct number of rows.
7pub fn repeat<E: Into<Expr>>(value: E, n: Expr) -> Expr {
8    let input = vec![value.into(), n];
9
10    let expr = Expr::Function {
11        input,
12        function: FunctionExpr::Repeat,
13        options: FunctionOptions {
14            flags: FunctionFlags::default()
15                | FunctionFlags::ALLOW_RENAME
16                | FunctionFlags::CHANGES_LENGTH,
17            ..Default::default()
18        },
19    };
20
21    // @NOTE: This alias should probably not be here for consistency, but it is here for backwards
22    // compatibility until 2.0.
23    expr.alias(PlSmallStr::from_static("repeat"))
24}