user
A   set   is a collection (container) of certain values,
without any particular order, and no repeated values.

It corresponds with a finite set in mathematics.

A set can be implemented as an associative array (partial mapping)
in which the value of each key-value pair is ignored.

Given a set S, the power set (or powerset) of S, written P(S), or 2S, is the set of all subsets of S.

Task

By using a library or built-in set type, or by defining a set type with necessary operations, write a function with a set S as input that yields the power set 2S of S.

For example, the power set of     {1,2,3,4}     is

:   :   :   {{}, {1}, {2}, {1,2}, {3}, {1,3}, {2,3}, {1,2,3}, {4}, {1,4}, {2,4}, {1,2,4}, {3,4}, {1,3,4}, {2,3,4}, {1,2,3,4}}.

For a set which contains n elements, the corresponding power set has 2n elements, including the edge cases of empty set.

The power set of the empty set is the set which contains itself (20 = 1):

:   :   :   P
            {\displaystyle {\displaystyle {\mathcal {P}}}}
            (

            ∅
            {\displaystyle {\displaystyle \varnothing }}
            ) = { 

            ∅
            {\displaystyle {\displaystyle \varnothing }}
             }

And the power set of the set which contains only the empty set, has two subsets, the empty set and the set which contains the empty set (21 = 2):

:   :   :   P
            {\displaystyle {\displaystyle {\mathcal {P}}}}
            ({

            ∅
            {\displaystyle {\displaystyle \varnothing }}
            }) = { 

            ∅
            {\displaystyle {\displaystyle \varnothing }}
            , { 

            ∅
            {\displaystyle {\displaystyle \varnothing }}
             } }

**Extra credit:**  Demonstrate that your language supports these last two powersets.
assistant
(formerly Perl 6)

**Works with**: rakudo version 2014-02-25

```
sub powerset(Set $s) { $s.combinations.map(*.Set).Set }
say powerset set <a b c d>;
```

Output:

```
set(set(), set(a), set(b), set(c), set(d), set(a, b), set(a, c), set(a, d), set(b, c), set(b, d), set(c, d), set(a, b, c), set(a, b, d), set(a, c, d), set(b, c, d), set(a, b, c, d))
```

If you don't care about the actual Set type, the .combinations method by itself may be good enough for you:

```
.say for <a b c d>.combinations
```

Output:

```
 
a
b
c
d
a b
a c
a d
b c
b d
c d
a b c
a b d
a c d
b c d
a b c d
```