2 ms·
Although the powerset discussed in the article is different than the one being discussed here, the most elegant powerset construction I've ever seen uses a meth
by sgk284 11y ago
Although the powerset discussed in the article is different than the one being discussed here, the most elegant powerset construction I've ever seen uses a method similar to what you described but abstracted away by the List monad in Haskell. The full implementation is:
powerset = filterM (const [True, False])
Which when ran will return:
>>> powerset [1,2,3,4]
[[1,2,3,4],[1,2,3],[1,2,4],[1,2],[1,3,4],[1,3],[1,4],[1],[2,3,4],[2,3],[2,4],[2],[3,4],[3],[4],[]]