<div dir="ltr">I'm thinking about how to separate pure functions from those that cause side effects, and one of the places I'm trying to find a decent pattern for is message passing.<div><br></div><div>I'm primarily concerned with being able to easily test the functional components as units, and then use integration testing for the parts that involve a side effect.</div><div><br></div><div>For instance, I have a gen_server that handles a message and emits an event sometimes.</div><div><br></div><div>handle_event_message(Arg, State=#state{collected_args=Args,event_server=Ev}) -></div><div>  gen_event:notify(Ev, {some_event, Arg}),</div><div>  State#state{collected_args[Arg |Args]}.</div><div><br></div><div>(obviously, I'm simplifying a lot here)</div><div><br></div><div>What I'm wondering about is extracting something like:</div><div><br></div><div><div>handle_event_message(Arg, State=#state{collected_args=Args,event_server=Ev}) -></div><div>  {Effects, State} = pure_handle(Arg, State),</div></div><div>  [ apply(Mod, Fun, Args) || {Mod, Fun, Args} <- Effects],</div><div>  State.</div><div><br></div><div>pure_handle(Arg, State) -></div><div>  { [{gen_event, notify, [Ev, {some_event, Arg}]}],</div><div>    State#state{collected_args[Arg |Args]} }.<br></div><div><br></div><div>Which would mean I could test the effects that pure_handle/2 intends in a unit test.</div><div><br></div><div>Is this a pattern others use? A terrible delusion? Not interesting?</div><div><br></div><div>Judson</div></div>