Skip to content
Browse files

lazy seq for lists

  • Loading branch information...
1 parent 769ec4d commit 2e2ac4d6553a2d94d5b96a745822083a56509f78 Andrey Stepachev committed
Showing with 9 additions and 2 deletions.
  1. +9 −2 apps/estockd/src/lazy.erl
View
11 apps/estockd/src/lazy.erl
@@ -1,11 +1,20 @@
-module(lazy).
-compile(export_all).
+-include_lib("eunit/include/eunit.hrl").
+
+
seq(M, N) when M =< N ->
fun() -> [ M, seq(M+1, N) ] end;
seq(_, _) ->
fun() -> [] end.
+seq([]) ->
+ fun() -> [] end;
+seq(List) ->
+ [ H | T ] = List,
+ fun() -> [ H, seq(T) ] end.
+
map_seq(Seq, P) ->
case Seq() of
[Val, NextSeq] ->
@@ -18,5 +27,3 @@ map_seq(Seq, P) ->
map_seq(M, N, P) ->
Seq = seq(M, N),
map_seq(Seq, P).
-
-

0 comments on commit 2e2ac4d

Please sign in to comment.
Something went wrong with that request. Please try again.