Skip to content

Instantly share code, notes, and snippets.

@loguntsov
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loguntsov/3db1ca7eb19944155da9 to your computer and use it in GitHub Desktop.
Save loguntsov/3db1ca7eb19944155da9 to your computer and use it in GitHub Desktop.
-module(merge).
-compile(export_all).
a(N) -> fun() -> [N|a(N+2)] end.
b(N) -> fun() -> [N|b(N+3)] end.
merge({A,B}) ->
[An|AFunc] = A(),
[Bn|BFunc] = B(),
if
An =:= Bn -> [ An| {AFunc, BFunc} ];
An < Bn -> [ An| { AFunc, B }];
Bn < An -> [ Bn| { A, BFunc }]
end.
c({A,B}) -> fun() -> [X| State ] = merge({A,B}), [X|c(State)] end.
test(Count, Fun) when Count > 0 ->
[X|Func] = Fun(),
[ X | test(Count - 1, Func ) ];
test(0, Fun) ->
[X|Func] = Fun(),
[X].
%test(10, c({A(1), B(1)}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment