Implement functor instance for Query