Skip to content

Instantly share code, notes, and snippets.

View ndpar's full-sized avatar

Andrey Paramonov ndpar

View GitHub Profile
class LazyList {
private Closure list
private LazyList(list) {
this.list = list
}
static LazyList nil() {
new LazyList( {-> []} )
-module(generic_server).
-export([start/0, loop/2]).
-export([request/1, change_state/1, change_function/1]).
%% Server
start() ->
register(?MODULE, spawn(?MODULE, loop, [2, fun erlang:'+'/2])).
-module(ring).
-export([start/3]).
-export([loop/1, loop/2]).
start(N, M, Message) when N > 1 -> spawn(fun() -> ring(N-1, M, Message) end).
ring(N, M, Message) when M > 0 ->
P = lists:foldl(fun(_, Proc) -> spawn(fun() -> loop(Proc) end) end, self(), lists:seq(1, N)),