public static IDisposable AffectEach <T>(this IReactiveCollection <T> collection, Action <IConnectionSink, T> affect) where T : class { var itemConnectionsDict = new Dictionary <T, Connections>(); collection.BindEach(item => { var itemConnections = new Connections(); if (itemConnectionsDict.ContainsKey(item)) { UnityEngine.Debug.LogError("it seems item is already loaded, this function wont work if elements repeated in the collection"); return; } affect(itemConnections, item); itemConnectionsDict[item] = itemConnections; }, item => { itemConnectionsDict.TakeKey(item).DisconnectAll(); }); return(new AnonymousDisposable(() => { foreach (var connections in itemConnectionsDict.Values) { connections.DisconnectAll(); } })); }