helper function for creating a listener from lamda