@@ -134,6 +134,8 @@ pub mod structs {
134134 pub use crate :: permutations:: Permutations ;
135135 pub use crate :: process_results_impl:: ProcessResults ;
136136 #[ cfg( feature = "use_alloc" ) ]
137+ pub use crate :: powerset:: Powerset ;
138+ #[ cfg( feature = "use_alloc" ) ]
137139 pub use crate :: put_back_n_impl:: PutBackN ;
138140 #[ cfg( feature = "use_alloc" ) ]
139141 pub use crate :: rciter_impl:: RcIter ;
@@ -207,6 +209,8 @@ mod peek_nth;
207209mod peeking_take_while;
208210#[ cfg( feature = "use_alloc" ) ]
209211mod permutations;
212+ #[ cfg( feature = "use_alloc" ) ]
213+ mod powerset;
210214mod process_results_impl;
211215#[ cfg( feature = "use_alloc" ) ]
212216mod put_back_n_impl;
@@ -1406,6 +1410,42 @@ pub trait Itertools : Iterator {
14061410 permutations:: permutations ( self , k)
14071411 }
14081412
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+
14091449 /// Return an iterator adaptor that pads the sequence to a minimum length of
14101450 /// `min` by filling missing elements using a closure `f`.
14111451 ///
0 commit comments