Created
December 14, 2012 09:42
-
-
Save Heimdell/4284090 to your computer and use it in GitHub Desktop.
Lazy list generator in erlang.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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