add compare function to a state class.