aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/small_SUITE_data/src/maybe_servers.erl
blob: 237f43b1a662921df065855548b45e74af5c7cb0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-module(maybe_servers).

-export([maybe_server/2, mirror_maybe_server/2]).

maybe_server(O, I) ->
    case O of
	no ->
	    maybe_loop(fun(_) -> fin end, I);
	yes ->
	    maybe_loop(fun(X) -> {ok, X} end, I)
    end.

maybe_loop(F, X)->
    case F(X) of
	{ok, Y} -> maybe_loop(F, Y);
	fin -> exit(n)
    end.

mirror_maybe_loop(F, X)->
    case F(X) of
	{ok, Y} -> mirror_maybe_loop(F, Y);
	fin -> exit(n)
    end.

mirror_maybe_server(O, I) ->
    case O of
	no ->
	    mirror_maybe_loop(fun(_) -> fin end, I);
	yes ->
	    mirror_maybe_loop(fun(X) -> {ok, X} end, I)
    end.