Skip to content

Instantly share code, notes, and snippets.

@Heimdell
Created December 14, 2012 09:42
Show Gist options
  • Save Heimdell/4284090 to your computer and use it in GitHub Desktop.
Save Heimdell/4284090 to your computer and use it in GitHub Desktop.
Lazy list generator in erlang.
-module (llist).
-compile(export_all).
unfold(X, F) ->
case F(X) of
{ok, X1} -> [X1 | fun() -> unfold(X1, F) end];
false -> []
end.
generator(Project, Last) ->
fun (X) ->
case Last(X) of
true -> false;
false -> {ok, Project(X)}
end
end.
head(LList) -> hd(LList).
tail(LList) -> (tl(LList))().
force([]) -> [];
force([Val | Next]) -> [Val | force(Next())].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment