@@ -1746,6 +1746,37 @@ impl<'ctx> Seq<'ctx> {
1746
1746
pub fn length ( & self ) -> Int < ' ctx > {
1747
1747
unsafe { Int :: wrap ( self . ctx , Z3_mk_seq_length ( self . ctx . z3_ctx , self . z3_ast ) ) }
1748
1748
}
1749
+
1750
+ /// Create a fold of the function `f` over the sequence with accumulator `a`.
1751
+ ///
1752
+ /// # Examples
1753
+ /// ```
1754
+ /// # use z3::{Config, Context, Solver, Sort};
1755
+ /// # use z3::ast::{Seq, Int, Dynamic, lambda_const};
1756
+ /// #
1757
+ /// # let cfg = Config::new();
1758
+ /// # let ctx = Context::new(&cfg);
1759
+ /// # let solver = Solver::new(&ctx);
1760
+ /// #
1761
+ /// let seq = Seq::new_const(&ctx, "seq", &Sort::int(&ctx));
1762
+ /// let accumulator = Int::new_const(&ctx, "acc");
1763
+ /// let item = Int::new_const(&ctx, "item");
1764
+ /// let sum = lambda_const(
1765
+ /// &ctx,
1766
+ /// &[&accumulator, &item],
1767
+ /// &Dynamic::from_ast(&Int::add(&ctx, &[&accumulator, &item])),
1768
+ /// );
1769
+ ///
1770
+ /// seq.foldl(&sum, &Dynamic::from_ast(&Int::from_u64(&ctx, 0)));
1771
+ /// ```
1772
+ pub fn foldl ( & self , f : & Array < ' ctx > , a : & Dynamic < ' ctx > ) -> Dynamic < ' ctx > {
1773
+ unsafe {
1774
+ Dynamic :: wrap (
1775
+ self . ctx ,
1776
+ Z3_mk_seq_foldl ( self . ctx . z3_ctx , f. z3_ast , a. z3_ast , self . z3_ast ) ,
1777
+ )
1778
+ }
1779
+ }
1749
1780
}
1750
1781
1751
1782
impl < ' ctx > Dynamic < ' ctx > {
0 commit comments