package main import ( "reflect" ) func filterChanges(in <-chan RaidState) <-chan RaidState { out := make(chan RaidState, 4) go func(in <-chan RaidState, out chan<- RaidState) { defer close(out) currentStates := map[string]RaidState{} for state := range in { if oldState, ok := currentStates[state.Name]; !ok || !reflect.DeepEqual(oldState.DevicesUp, state.DevicesUp) { currentStates[state.Name] = state out <- state } } }(in, out) return out }