|
@@ -6,7 +6,8 @@
|
|
|
value/1, values/1,
|
|
|
pipe/1, par/1,
|
|
|
route/3, sync/1,
|
|
|
- split/1, merge/1, switch/2]).
|
|
|
+ split/1, merge/1,
|
|
|
+ switch/1]).
|
|
|
|
|
|
%%% Operation querying
|
|
|
-export([in_arity/1, out_arity/1, flatten_arity/1, can_connect/2]).
|
|
@@ -64,17 +65,16 @@ split(N) when is_number(N) -> #split{size=N}.
|
|
|
|
|
|
merge(N) when is_number(N) -> #merge{size=N}.
|
|
|
|
|
|
-switch(N, Map = [_|_]) when is_number(N) ->
|
|
|
- SMap = lists:ukeysort(2, Map),
|
|
|
- try
|
|
|
- lists:foldl(fun({_T_I, I}, Prev_I) when I == 1+Prev_I -> I;
|
|
|
- ({_T_I, _I}, _Prev_I) -> throw(missing_path)
|
|
|
- end,
|
|
|
- 0, SMap)
|
|
|
- of
|
|
|
- I -> #switch{in=1+N, out=I*N, map=SMap}
|
|
|
- catch
|
|
|
- throw:missing_path -> erlang:error(badarg, [N, Map])
|
|
|
+switch(Map = [{_Tag1, Op1}|Rest]) ->
|
|
|
+ In = in_arity(Op1),
|
|
|
+ Out = out_arity(Op1),
|
|
|
+ Match = lists:all(fun({_T_I, Op}) ->
|
|
|
+ in_arity(Op) == In andalso out_arity(Op) == Out
|
|
|
+ end,
|
|
|
+ Rest),
|
|
|
+ case Match of
|
|
|
+ true -> #switch{in=1+In, out=Out, map=Map};
|
|
|
+ false -> erlang:error(badarg, [Map])
|
|
|
end.
|
|
|
|
|
|
%%%-----------------------------------------------------------------------------
|