Skip to content

Instantly share code, notes, and snippets.

@nicolasff
Created January 10, 2011 17:04
Show Gist options
  • Save nicolasff/773056 to your computer and use it in GitHub Desktop.
Save nicolasff/773056 to your computer and use it in GitHub Desktop.
Allowed elements in a set.
-module(test).
-export([allowed/1]).
% null case
allowed([]) ->
[];
% single element case
allowed([E]) ->
[[E]];
% allowed for H|T is H only, and all that is allowed for T,
% as well as that same set with H included.
allowed([H|T]) ->
L = allowed(T),
L ++ [[H]] ++ lists:map(fun(E) -> [H|E] end, L).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment