public IObservable <Tuple <Target, Message> > Map <Source, Target>(IObservable <Tuple <Source, Message> > source, IDictionary <Source, Target> target_by_source) { return(RX.Create <Tuple <Target, Message> >(observer => { return source.Subscribe( source_node_message => { try { Target target_node; bool found_target; using (Concurrency.ReaderLock(_mutex)) { found_target = target_by_source.TryGetValue(source_node_message.Item1, out target_node); } if (found_target) { var target_node_message = Tuple.Create(target_node, source_node_message.Item2); observer.OnNext(target_node_message); } } catch (Exception error) { observer.OnError(error); } }, observer.OnError, observer.OnCompleted ); })); }