:- module(broadcast_streams,
          [
            new_broadcast_stream/2     % +StreamsIn, +NewStream
          ]).



:- use_module(library(predicate_streams)).
:- use_module(library(yall)).

%! new_broadcast_stream(+list:StreamsIn,-NewStream)
%
%  Creates a new output stream that each write 
%  outputs to all of the output streams

new_broadcast_stream(List,Stream):- 
  new_predicate_output_stream([Data]>>forall(member(S,List),write(S,Data)),Stream).

:- if(false).
new_broadcast_stream(List,Stream):-
  new_predicate_output_stream(write_to_streams(List),Stream).
write_to_streams(List,Data):- maplist(write_rev(Data),List).
write_rev(Data,Stream):- write(Stream,Data).
:- endif.
