@@ -134,6 +134,8 @@ pub mod structs {
134
134
pub use crate :: permutations:: Permutations ;
135
135
pub use crate :: process_results_impl:: ProcessResults ;
136
136
#[ cfg( feature = "use_alloc" ) ]
137
+ pub use crate :: powerset:: Powerset ;
138
+ #[ cfg( feature = "use_alloc" ) ]
137
139
pub use crate :: put_back_n_impl:: PutBackN ;
138
140
#[ cfg( feature = "use_alloc" ) ]
139
141
pub use crate :: rciter_impl:: RcIter ;
@@ -207,6 +209,8 @@ mod peek_nth;
207
209
mod peeking_take_while;
208
210
#[ cfg( feature = "use_alloc" ) ]
209
211
mod permutations;
212
+ #[ cfg( feature = "use_alloc" ) ]
213
+ mod powerset;
210
214
mod process_results_impl;
211
215
#[ cfg( feature = "use_alloc" ) ]
212
216
mod put_back_n_impl;
@@ -1406,6 +1410,42 @@ pub trait Itertools : Iterator {
1406
1410
permutations:: permutations ( self , k)
1407
1411
}
1408
1412
1413
+ /// Return an iterator that iterates through the powerset of the elements from an
1414
+ /// iterator.
1415
+ ///
1416
+ /// Iterator element type is `Vec<Self::Item>`. The iterator produces a new `Vec`
1417
+ /// per iteration, and clones the iterator elements.
1418
+ ///
1419
+ /// The powerset of a set contains all subsets including the empty set and the full
1420
+ /// input set. A powerset has length _2^n_ where _n_ is the length of the input
1421
+ /// set.
1422
+ ///
1423
+ /// Each `Vec` produced by this iterator represents a subset of the elements
1424
+ /// produced by the source iterator.
1425
+ ///
1426
+ /// ```
1427
+ /// use itertools::Itertools;
1428
+ ///
1429
+ /// let sets = (1..4).powerset().collect::<Vec<_>>();
1430
+ /// itertools::assert_equal(sets, vec![
1431
+ /// vec![],
1432
+ /// vec![1],
1433
+ /// vec![2],
1434
+ /// vec![3],
1435
+ /// vec![1, 2],
1436
+ /// vec![1, 3],
1437
+ /// vec![2, 3],
1438
+ /// vec![1, 2, 3],
1439
+ /// ]);
1440
+ /// ```
1441
+ #[ cfg( feature = "use_alloc" ) ]
1442
+ fn powerset ( self ) -> Powerset < Self >
1443
+ where Self : Sized ,
1444
+ Self :: Item : Clone ,
1445
+ {
1446
+ powerset:: powerset ( self )
1447
+ }
1448
+
1409
1449
/// Return an iterator adaptor that pads the sequence to a minimum length of
1410
1450
/// `min` by filling missing elements using a closure `f`.
1411
1451
///
0 commit comments